nightkarnation Posted June 28, 2012 Share Posted June 28, 2012 Hey guys, I have the following: $last_free_date = 'Wed Jun 27 20:32:51 GMT-0300 2012'; $One_Day_Secs = '86400'; $server_current_time = date('D M j H:i:s \G\M\TO Y',strtotime('-'. $One_Day_Secs . 'seconds')); //returns a different date but with the same format as $last_free_date //Below is the problem: $last_free_date is not being properly recognized...so sometimes I get that $last_free_date is less than $server_current_time when its actually not...or vice verza...any ideas?? if ($last_free_date < $server_current_time) { //etc... } Quote Link to comment https://forums.phpfreaks.com/topic/264958-turn-a-string-variable-with-date-format-into-a-date-variable/ Share on other sites More sharing options...
Pikachu2000 Posted June 28, 2012 Share Posted June 28, 2012 You can't directly compare the two strings. They would need to be in most-to-least significant value order (YYYY-MM-DD hh:mm:ss) to compare them as strings, otherwise you need to strtotime them for comparison. If the values are coming from a database query, you could simply select only the values that meet the criteria of the comparison. Quote Link to comment https://forums.phpfreaks.com/topic/264958-turn-a-string-variable-with-date-format-into-a-date-variable/#findComment-1357764 Share on other sites More sharing options...
nightkarnation Posted June 28, 2012 Author Share Posted June 28, 2012 Thanks a lot Pikachu!! The following seems to work correctly: $last_free_date = strtotime($last_free_date); $server_current_time = strtotime($server_current_time); if ($last_free_date < $server_current_time) {... Quote Link to comment https://forums.phpfreaks.com/topic/264958-turn-a-string-variable-with-date-format-into-a-date-variable/#findComment-1357767 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.