I have an insert server action to a table with a field set to datetime.
I have set the value in the database insert to both NOW and NOW_UTC. I am getting the same time for both which appears to be UTC minus 5 hours.
Most odd - I am using Siteground as the hosting provider. Any thoughts ?
That is probably the timezone the server is configured in. NOW_UTC however should insert the UTC time. Which Server Model (PHP, ASP) are you using and which Database Server?
Server model is PHP and the database server is MySQL
In the screenshot then the first record is NOW and the other three are NOW_UTC

It seems that this is actually the correct behavior with mySQL. Depending on the timezone that PHP is configured in, the NOW
will return something like 2020-04-29T10:30:00
and UTC_NOW
will return something like 2020-04-29T07:30:00Z
. The Z
at the end means that it is a UTC timestamp.
mySQL doesn’t have special date fields for timezones, it stores all datetimes as UTC internally. So it converts the given date to a UTC datetime and when read it will convert it to the timezone mySQL is configured in.
mySQL will recognize the Z
as UTC timezone and the other string will be handled as a local timezone, so both are stored as the same datetime.
This is the case for mySQL, Postgres for example has fields with or without timezones and does not convert the dates automatically.
1 Like