Jump to content

Archived

This topic is now archived and is closed to further replies.

glenelkins

Comparing Dates

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
ah yes, im a dumb ass lol.

cheers Crayon

Share this post


Link to post
Share on other sites

×

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.