How do I know if I have to use NOW or NOW_UTC?

How do I know if I have to use NOW or NOW_UTC when inserting current time into a database row?

I’m using NodeJS, MariaDB and PostgreSQL

NOW gives you time based on your server locale.
NOW_UTC gives time based on universal time constant otherwise known as Greenwich mean time where time offset is zero.

On top of Brian's reply, just to be clear NOW gives you local server time/date not the user time/date.

1 Like

Yes, really should have said server locale, that's really important

1 Like

and how does one get the user time?

Hi jimed99,

There are two methods:

  1. If you are getting user submitted information, then to get user's local time, use datetime component on the front end and submit that along with the other form information.
  2. If you want to use user's local datetime information for server side operations, then you will need to keep a record of user's timezone and calculate the time difference from the UTC or server time to arrive at the user's local time.
1 Like

Another option is using the IP and look for an API that retrieves the data, for example:

Time Zone America/Argentina/Buenos_Aires (-0300)

So you do UTC - 03 hs and get the time of the user

I vaguely remember talks about database driver configuration and time, and people were experiencing unexpected times, that was the source of my question

Thinking of this?

1 Like