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
https://forums.phpfreaks.com/topic/259758-how-can-i-make-strtotime-more-accurate/
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);

 

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.