Re: date comparison

From: Date: Mon, 15 Jan 2001 14:51:02 +0000
Subject: Re: date comparison
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-34627@lists.php.net to get a copy of this message
The way you want to do this is with UNIX timestamps. FYI a timestamp is the number of seconds starting at 1970 and going up (it's important to remember that date - since some people were born before, etc.) So you need to do this: $dateA = '12-25-1999'; $dateB = '12-24-1999'; // convert to unix time stamps $fooA = explode('-',$dateA); $fooB = explode('-',$dateB); $timestampA = mktime(0,0,0,$fooA[0],$fooA[1],$fooA[0]); $timestampB = mktime(0,0,0,$fooB[0],$fooB[1],$fooB[0]); if($timestampA > $timestampB) { echo $dateA . " is greater than B"; } Hope this helps - you can also check out this page: http://www.php.net/manual/en/ref.datetime.php --Joe On Mon, Jan 15, 2001 at 12:00:05PM -0600, Jacky@lilst wrote: > Greeting all, > Just now I asked about to tie string values together and would like to thank > Jason for that. Anyway one more thing, after I have tied string values > together and assigned that to a virables. can I used the value from that > variables to compare with another date value? Say another date value I will > use is also retrieved from a field in table which is in Date data type as > well. So it will be like > > > $query = "select myBirthdate from date where userId='1' "; > $dateResult =mysql_query($query); > $myBirthDate = (mysql_result($dateResult,0,"myBirthdate")); > > $thisBirthdate = "$year"."$month"."$day"; > > if ($thisBirthdate < $myBirthdate) { > do something > } else { > do some other thing > } > > Is it the correct way to do that? > cheers > Jack > jacky@activelifestyle.com > "There is nothing more rewarding than reaching the goal you set for > yourself" > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net -- Joe Stump, PHP Hacker joestump98@yahoo.com http://www.miester.org/

« previous php.general (#34627) next »