Jump to content

Comparing Dates


glenelkins

Recommended Posts

Hi

The following lines of code generate 2 dates. Now i want to compare if($weddingdate <= $groupdate) but this does not do anything. How would I compare the two?

[code]
$temp_wd = explode("-",$_POST['date']);
$weddingdate = date("Y-m-d",mktime(0,0,0,$temp_wd[1],$temp_wd[0],$temp_wd[2]));

$temp_gd = explode("-",$_POST['groupdate']);
$groupdate = date("Y-m-d",mktime(0,0,0,$temp_gd[1],$temp_gd[0],$temp_gd[2]));
[/code]

cheers

g
Link to comment
Share on other sites

the date function creates a string. you can't compare if one string is less than or equal to another string.  For example, what do you expect php to do if you do this?

if ('apples' <= 'oranges') { .. }

you need to do like this:

[code]
$temp_wd = explode("-",$_POST['date']);
$wed = mktime(0,0,0,$temp_wd[1],$temp_wd[0],$temp_wd[2]);
$weddingdate = date("Y-m-d", $wed);

$temp_gd = explode("-",$_POST['groupdate']);
$group = mktime(0,0,0,$temp_gd[1],$temp_gd[0],$temp_gd[2]);
$groupdate = date("Y-m-d",$group);

if ($wed <= $group) { .. }
[/code]
the mktime() function creates the unix timestamp which is an integer value, which CAN be compared properly.
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.