0

I have a database table in (Drupal) which time is stored in a format like 1328105887 . I want to write a where condition w.r.t. this date where is year is 2014 and output date will be in (d-m-y) format.

My table sturcture is like this

SELECT `sid`,`nid`,`uid`,`is_draft`,`submitted`,`remote_addr` FROM `my_table`

Help me to achieve this only with mysql query .

Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54
Vipul sharma
  • 1,245
  • 1
  • 13
  • 33
  • 3
    possible duplicate of [Convert timestamp to date in MySQL query](http://stackoverflow.com/questions/9251561/convert-timestamp-to-date-in-mysql-query) – Jim Wright Jun 04 '15 at 07:15
  • 2
    Which is this format ? Can you tell the equivalent date for **1328105887**? – Akhil Jun 04 '15 at 07:18

2 Answers2

1
SELECT  from_unixtime(1328105887) from tableName
returns : 2012-02-01 19:18:07

Now

 SELECT DATE_FORMAT(from_unixtime(1328105887) ,'%m-%d-%Y') 
 returns: 02-01-2012

if you need just year use this:

 SELECT DATE_FORMAT(from_unixtime(1328105887) ,'%Y') 
 returns: 2012

use it in where clause as:

where DATE_FORMAT(from_unixtime(1328105887) ,'%Y')='2014'

so the final query would be

  SELECT `sid`,`nid`,`uid`,`is_draft`,`submitted`,`remote_addr` FROM 
  `my_table` 
  where DATE_FORMAT(FROM_UNIXTIME(`date_column`),'%Y') = '2014'
Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78
0

Working

SELECT DATE_FORMAT(FROM_UNIXTIME(submitted), '%d-%m-%Y') AS 'date_formatted' FROM ma_webform_submissions where year(FROM_UNIXTIME(submitted)) = '2014'

Vipul sharma
  • 1,245
  • 1
  • 13
  • 33