aj_nsc
03-19-2007, 08:40 AM
As you can see in this forum as an example, certain posts are marked last updated as "Today" and "Yesterday". I am doing something similar right now where I am storing a datetime field and I want to determine if the value is from today, yesterday, or other. What's the SQL, I haven't come across it before. Thanks.
(Using MySQL 5.02)
NightShift58
03-20-2007, 04:38 AM
I think you would want to deal with that in your PHP (or whichever) script rather than at the SQL level.
You would retrieve the dates normally, sorted in whichever order you chose, and in your script (PHP in this example):<?php
$today = date("Y-m-d");
$yesterday = date("Y-m-d", time() - 86400);
WHILE ($row = mysql_fetch_array($query)) :
IF (substr($row['date_field'],0,10) == $today) :
$thisTIMELINE = "Today, " . substr($row['date_field'],10);
ELSEIF (substr($row['date_field'],0,10) == $yesterday) :
$thisTIMELINE = "Yesterday, " . substr($row['date_field'],10);
ELSE :
$thisTIMELINE = $row['date_field'];
ENDIF;
echo $thisTIMELINE;
ENDWHILE;
?>