This simple PHP example will return a date and time format like facebook, generated from a mysql datetime field. Input Format: date('Y-m-d H:i:s')
<?php /* Online PHP Examples with Source Code website: http://4evertutorials.blogspot.in/ */ function getDateTime($datetime) { $datetime=strtotime($datetime); $yesterday=strtotime(date('Y-m-d', mktime(0,0,0, date("m") , date("d") - 1, date("Y")))); $tomorrow=strtotime(date('Y-m-d', mktime(0,0,0, date("m") , date("d") + 1, date("Y")))); $time=strftime('%H:%M',$datetime); $date=strftime('%e %b %Y',$datetime); if($date==strftime('%e %b %Y',strtotime(date('Y-m-d')))) { $date="Today"; } elseif($date==strftime('%e %b %Y',$yesterday)) { $date="Yesterday"; } elseif($datum==strftime('%e %b %Y',$tomorrow)) { $date="Tomorrow"; } return $date." at ".$time; } ?>
0 comments:
Post a Comment