Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert javascript date to php date format
    primarykey
    data
    text
    <p>I'm using a <a href="http://www.eyecon.ro/bootstrap-datepicker/" rel="nofollow">jQuery datepicker</a> where obviously the date format doesn't match php format.</p> <p>How could I convert the datepicker format over to php format so that I can output <code>date( $format )</code> in the same convention defined in the datepicker format. So say I put the format like <code>dd/mm/yyyy</code>, how could I convert that to <code>m/d/o</code> in php? Or if I specified it as <code>d-m-yy</code>, how to convert that to <code>n-j-y</code>?</p> <p>Basically, wondering how I could convert the allowed date picker formats, regardless of what the letters or the separators are to php.</p> <p>I've tried using preg_replace, but the issue there is with single and double same letters. <code>dd</code> becomes <code>nn</code>, since it's trying to replace <code>d</code> twice. Could something with regex be used maybe? I'm kind of lost on how the logic to convert would be done.</p> <p><strong>Edit</strong>: My Apologies for a oversight in the details. The js format is literally like <code>dd/mm/yyyy</code>, 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 - <em>sigh</em>).</p> <p><strong>Edit#2</strong> Here's a working script up on Codepad, which shows the issue with letters in the format being treated individually and doubled up. <code>mm</code> becomes <code>nn</code> instead of just being <code>m</code>. The rest of the characters are being individualized as well.</p> <p><a href="http://codepad.org/lBgqVgbs" rel="nofollow">http://codepad.org/lBgqVgbs</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload