Jump to content

How Can I make StrtoTime() More Accurate ?


vincej

Recommended Posts

Hi - I have an HTML form where the customer can amend text dates. However, I have noticed that if you for example change 01 Jun 2012 to something like, 01 July 2012, 50% of the occasions, strtotime() will ignore the change and just go back to 01 jun 2012.

 

This is not unique to June, is there anything I can do to make things better ??

 

Thanks !

Link to comment
Share on other sites

This is not a problem with strtotime().  You are not storing the new value or some other issue.

 

Agreed. strtotime() will always interpret the same input as the same value. Note, there *could*be some differences on how one server would interpret based upon the locale settings of that server (not 100% sure), but each server would always interpret the same input as the same value. For me, running "01 July 2012" through strtotime() interprests it correctly as the first day of July in the year 2012. So, your problem, must be due to some other problem. If the user is entering the dates directly the interpretation of strtotime() can be affected by certain formatting.

 

You can easily verify whether strtotime() is generating the right result by adding some debugging code. For example:

$user_input = $_POST['new_date'];
$new_date = strtotime($user_input);

echo "Date from user: {$user_input}<br>\n";
echo "Date from strtotime: " . date('F j, Y', $new_date);

 

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.