I'm using a jQuery datepicker where obviously the date format doesn't match php format.
How could I convert the datepicker format over to php format so that I can output date( $format )
in the same convention defined in the datepicker format. So say I put the format like dd/mm/yyyy
, how could I convert that to m/d/o
in php? Or if I specified it as d-m-yy
, how to convert that to n-j-y
?
Basically, wondering how I could convert the allowed date picker formats, regardless of what the letters or the separators are to php.
I've tried using preg_replace, but the issue there is with single and double same letters. dd
becomes nn
, since it's trying to replace d
twice. Could something with regex be used maybe? I'm kind of lost on how the logic to convert would be done.
Edit: My Apologies for a oversight in the details. The js format is literally like dd/mm/yyyy
, not the actual date output. What it is, in the CMS, the user defines the format the datepicker uses (dd/mm/yyyy or any other format sequence and separators the datepicker has). The PHP is used to output the current date using that defined format and sequence. I would love to have them define a PHP format and then convert that to the js format. But the powers that be always want things the way they want them - sigh).
Edit#2
Here's a working script up on Codepad, which shows the issue with letters in the format being treated individually and doubled up. mm
becomes nn
instead of just being m
. The rest of the characters are being individualized as well.