Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change 22nd Jan 2008 16:15:27 to Today 16:15.27

Status
Not open for further replies.

JamesGMills

Programmer
Aug 15, 2005
157
GB
Hello!

Now most of you will have seen when you are using a site that shows you dates of when things have happened if its happened today or yesterday then it will not show you the date it will actually say Today 15:35, or Yesterday 16:10...

Is this possible using SQL or is there something you can do on the date returned?

I am using datetime in mysql to store the date of something being added.

This is my SQL

SELECT *,date_format(DateAdded, '%D %b %Y %T') as DateAddedFormatted FROM $this->tablename

This will bring back something like: 22nd Jan 2008 16:15:27

Anyone got any advice/help on this one...

Thanks



------------------------
 
Got it sorted in the end, thanks.

$yesterday = mktime(0,0,0,date("m"),date("d")-1,date("Y"));
$today = mktime(0,0,0,date("m"),date("d"),date("Y"));
$myDate = strtotime("2008-01-22 00:42:03");

if($myDate > $today)
{
$msg = 'Today ' . date("h:ia", $myDate);
}
else if($myDate > $yesterday && $myDate < $today)
{
$msg ='Yesterday ' . date("h:ia", $myDate);
}
else
{
$msg = date("d/m/Y h:i:s", $myDate);
}

echo $msg;

------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top