convert time format in mysql query -
i have database table in (drupal) time stored in format 1328105887 . want write where condition w.r.t. date year 2014 , output date in (d-m-y) format.
my table sturcture this
select `sid`,`nid`,`uid`,`is_draft`,`submitted`,`remote_addr` `my_table`
help me achieve mysql query .
select from_unixtime(1328105887) tablename returns : 2012-02-01 19:18:07
now
select date_format(from_unixtime(1328105887) ,'%m-%d-%y') returns: 02-01-2012
if need year use this:
select date_format(from_unixtime(1328105887) ,'%y') returns: 2012
use in clause as:
where date_format(from_unixtime(1328105887) ,'%y')='2014'
so final query be
select `sid`,`nid`,`uid`,`is_draft`,`submitted`,`remote_addr` `my_table` date_format(from_unixtime(`date_column`),'%y') = '2014'
Comments
Post a Comment