Jump to content

Turn a string variable with Date format into a Date Variable


nightkarnation

Recommended Posts

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...
}

Link to comment
Share on other sites

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.

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.