Re: PHP <-> MySQL Timestamp Storage and Comparison

From: Date: Sat, 30 Sep 2000 06:44:47 +0000
Subject: Re: PHP <-> MySQL Timestamp Storage and Comparison
Groups: php.general 
Request: Send a blank email to php-general+get-18150@lists.php.net to get a copy of this message
Addressed to: "Gary Singleton" <gsinglet2@yahoo.com> php-general@lists.php.net ** Reply to note from "Gary Singleton" <gsinglet2@yahoo.com> Fri, 29 Sep 2000 16:50:47 -0700 > > I am trying to find the best way of storing time values in MySQL so I can= > compare them later. DateTime and Timestamp. See: http://www.mysql.com/documentation/mysql/commented/manual.php?section=Column_types > if (($date_updated - $date_original) <=3D ($day * 3) && ($date_current -= > $date_updated) <=3D ($day * 3)) { > echo "new"; > } > elseif (($date_updated - $date_original) > ($day * 3) && ($date_current -= > $date_updated) < ($day * 3)) { > echo "updated"; >} >else { > echo "old"; >} How about doing it with MySQL? SELECT IF( ADDDATE( date_updated, INTERVAL 3 DAYS ) < NOW(), 'old', IF( ADDDATE( date_original, INTERVAL 3 dAYS) < NOW(), 'updated', 'new' )) AS age_tag; This returns a value named 'age_tag' that is set to: if record was created in the last 3 days : new if it was created earlier, but updated in the last 3 days: updated else: old. In MySQL the IF( construct works like: IF( conditional_statement, return_if_true, return_if_false ); You should also look at: http://www.mysql.com/documentation/mysql/commented/manual.php?section=Date_and_time_functions> It is all in the manual... Rick Widmer Internet Marketing Specialists www.developersdesk.com

« previous php.general (#18150) next »