vincej Posted March 26, 2012 Share Posted March 26, 2012 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 ! Quote Link to comment https://forums.phpfreaks.com/topic/259758-how-can-i-make-strtotime-more-accurate/ Share on other sites More sharing options...
AbraCadaver Posted March 26, 2012 Share Posted March 26, 2012 This is not a problem with strtotime(). You are not storing the new value or some other issue. Quote Link to comment https://forums.phpfreaks.com/topic/259758-how-can-i-make-strtotime-more-accurate/#findComment-1331329 Share on other sites More sharing options...
Psycho Posted March 26, 2012 Share Posted March 26, 2012 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); Quote Link to comment https://forums.phpfreaks.com/topic/259758-how-can-i-make-strtotime-more-accurate/#findComment-1331334 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.