Jump to content

strtotime - what constitutes "english textual datetime"?


ahs10

Recommended Posts

so from the manual the description is...

 

strtotime — Parse about any English textual datetime description into a Unix timestamp

 

i'm trying to find a more specific way to define "english textual datetime".  if just dealing with date shorthand formats (ex - mm/dd/yy), would it be safe to say any format that lists the month before the day?  is that accurate?

Link to comment
Share on other sites

It's actually very impressive what it can do.. pretty much any way you might write the date, it will figure it out. so

February 21, 2008

2008-02-21

2/21/08

 

I'm pretty sure it would get all of them. Best thing to do is to pick one, make sure it works, then use it consistently for your site.

Link to comment
Share on other sites

nope, from previous experience i know proper sql datetime format (yyyy-mm-dd) does not work.  that's not a English datetime description (although the one that makes the most sense).

 

that's why i'm trying to grasp the limitations of that term.  if i were dealing with dates on my site, i would be consistent, but this is a hard situation to explain.  none the yahoo, i'd still like to find the scope of the term "english textual datetime".  thanks!

Link to comment
Share on other sites

Actually, it does. I use the Mysql format on my site and it works perfectly. If $date has been grabbed from the mysql database (in yyyy-mm-dd format), then

 

$time_s = strtotime($date);

$date = date("F j, Y", $time_s);

 

gives me a new string $date that will display 'February 21, 2008' format.

Link to comment
Share on other sites

nope, from previous experience i know proper sql datetime format (yyyy-mm-dd) does not work. that's not a English datetime description (although the one that makes the most sense).

Although it may not be specifically English it is an ISO standard called ISO 8601.

 

Edit: As specified in the PHP manual can you see all the supported formats here: http://www.gnu.org/software/tar/manual/html_node/tar_113.html

Link to comment
Share on other sites

thanks for that gnu link, that's perfect.

 

so i still hold on to the belief that yyyy-mm-dd does not work with strtotime all the time.  i remember a couple of months back posting an issue with that.  the solution provided to me was a great tutorial on using DATE_FORMAT and STR_TO_DATE in your db queries.

 

anyweezer, thanks for the discussion and i believe that link was just what i needed.  thanks again!

 

 

 

Link to comment
Share on other sites

Here's a script to check out various acceptable formats

 

<?php 
$formats = array(
              'Y-m-d',  
              '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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.