Jatin Seth
Jatin Seth

Reputation: 312

Getting different result using Mysql UNIX_TIMESTAMP() to JAVASCRIPT Date.UTC()

I need to supply the values of Javascript Date.UTC() to an array of graph. When I am doing it manually like Date.UTC(2016, 2, 21) which is equivalent to '2016-03-21' then it's working fine but I need to fetch the results from Mysql not manually so I am using UNIX_TIMESTAMP('2016-03-21') * 1000 but the strange thing is I am getting different result for both. How to make same ?

Date.UTC(2016, 2, 21) = 1458518400000
UNIX_TIMESTAMP('2016-03-21') * 1000 = 1458498600000

Upvotes: 0

Views: 58

Answers (1)

Jatin Seth
Jatin Seth

Reputation: 312

The problem was I needed to covert the timezone first to match the results by using following statement

set time_zone = 'value'

Upvotes: 1

Related Questions