Jump to content


Photo

Comparing Dates


  • Please log in to reply
2 replies to this topic

#1 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 06 July 2006 - 07:34 AM

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?

$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]));

cheers

g
http://thewebsolutionprovider.com - A Solution For Everything Web!

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 06 July 2006 - 07:43 AM

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:

$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) { .. }
the mktime() function creates the unix timestamp which is an integer value, which CAN be compared properly.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 glenelkins

glenelkins
  • Members
  • PipPipPip
  • Advanced Member
  • 760 posts
  • LocationBridlington - East Riding of Yorkshire - United Kingdom

Posted 06 July 2006 - 07:46 AM

ah yes, im a dumb ass lol.

cheers Crayon
http://thewebsolutionprovider.com - A Solution For Everything Web!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users