Alan
Alan

Reputation: 379

How to change timezone of NOW() in mySQL Database in Node.js query?

How can i change the timezone of the NOW() function in mySQL, I'm doing a insert with Node.js. Or maybe even change the timezone to the whole database since I have the Default set to current timestamp.

What is the best approach? Do it via Node.js at my insert, or change (if possible) the timezone of the whole database.

Upvotes: 0

Views: 574

Answers (1)

Dancrumb
Dancrumb

Reputation: 27539

"Best" approach invites opinions rather than definitive answers. However, there are some compelling reasons to adopt the following:

Set your database to UTC. It makes timezone conversion much simpler.

In theory, you could lock it to any timezone, but most others are geographically associated and many geographies change their timezone throughout the year. UTC makes things much more cut and dry.

Then, when you application receives data from the database, it knows that it is in UTC and can do any necessary conversion to the "local" timezone where necessary.

Upvotes: 1

Related Questions