5

How do I convert big int to date

Sample output:

name               due
release          | 1300150800000000 

Description:

| name        | text       | NO   | PRI | NULL    |       |
| due         | bigint(20) | YES  |     | NULL    |       |
gideon
  • 19,329
  • 11
  • 72
  • 113
Efox
  • 651
  • 3
  • 8
  • 19

2 Answers2

17

It seems it contains microseconds since 1970-Jan-01 00:00:00am GMT.

That is after converting your value to seconds, it gives 1300150800, which is equivalent to 2011-Mar-15 01:00:00am GMT.

Therefore to convert it to a datetime you can use MySQL's FROM_UNIXTIME(unix_timestamp, format) after converting it to seconds (by dividing 1000000).

SQL:

SELECT FROM_UNIXTIME(due/1000000, "%Y-%m-%d %H:%i:%s") AS due_date 
FROM   MyTable;

Ref:

Amil Waduwawara
  • 1,632
  • 1
  • 16
  • 14
  • @efox, It seems you're new to StackOverflow. Please accept if you got the answer. – Amil Waduwawara Mar 28 '11 at 04:20
  • 1
    It appears FROM_UNIXTIME() would introduce the [Y2K38 problem](http://stackoverflow.com/a/2012620/673991). Wonder if there's an alternative that doesn't. Otherwise (calculator tapping sounds) BIGINT seems good to year 9999 even counting microseconds. – Bob Stein Jul 30 '13 at 17:19
0

select CAST( from_unixtime(end_time/1000) as DATE) from myTable ;

Output: 2015-03-01

Allwin
  • 2,060
  • 1
  • 17
  • 16