php - mysql special date output format -
as part of live chat script uses php/mysql on serverside , js/jquery on clientside want output date of each message in special format.
if message send today this(for example): today 22:30
, if sent yesterday : yesterday 12:30
, if send before yesterday should output date format: dd.mm.yy h:i (for example 28.05.14 22:19)
.
of course know php easily, better performance want using sql.
i´ve read lot in mysql documentation altough found lot of date formating, couldn´t find this.
now want know if possible sql?
the date of each message stored timestamp in db.
use query below. must fulfill requirements(with or without modifications).
select if(date_format(`created`, '%y-%m-%d') = date(now()), 'today ' + date_format(`created`, '%k:%i'), (select if(date_format(`created`, '%y-%m-%d') < date(now()), (select if(date_format(`created`, '%y-%m-%d') = (date(now() - interval 1 day)), 'yesterday ' + date_format(`created`, '%k:%i'), date_format(`created`, '%d-%m-%y %k:%i'))), 'no display' ) ) ) user;
note: here 'created' date intending fetch user table.
for date_format ( ) function description , parameters used check link http://www.w3schools.com/sql/func_date_format.asp
hope helps . . .
Comments
Post a Comment