Jump to content

strtotime(date('m/d/Y'))


gerkintrigg

Recommended Posts

does the following code give the correct time:?

strtotime(date('m/d/Y'))

or do I need to use :

strtotime(date('d/m/Y'))

?

I tried to find out which way the month and day work, but can't seem to find anything that will tell me.

 

I know i did it before but can't put my hands on the code.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/75843-strtotimedatemdy/
Share on other sites

strtotime will accept quite a few formats.

 

d/m/y is NOT one of them

 

Easy enough to test which ones work

 

<?php 
$formats = array(
              'm/d/Y',
              'd/m/Y',
              'm-d-Y',
              'd-m-Y',
              'd-M-Y',
              'd F Y',
              'F d Y'
);

echo '<table border="1">';
    echo '<tr><td>Format</td><td>Today</td><td>strtotime()</td><td>OK?</td></tr>';
foreach  ($formats as $f)
{
    $res = date ('d M Y', strtotime (date($f)));
    $OK = $res == date('d M Y') ? 'OK' : 'X';
    echo '<tr><td>', $f, '</td><td>', date($f), '</td><td>', $res, '</td><td>', $OK, '</td></tr>';
}
echo '</table>';

?>

Link to comment
https://forums.phpfreaks.com/topic/75843-strtotimedatemdy/#findComment-383934
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.