How to get the date from the database as UTC?
hi. In my api I add dates to the database in UTC format, but when I take them out of the database and want to return, they are not in UTC format (no 'Z' at the end). Is it possible to get them some UTC without conversion?
6 Replies
this is going to depend highly on what specific database you're using, and the datatype of the column in question
you might also want to consider storing unix timestamps instead - sidesteps this issue
I'm using postgresql with datetime2 column type
Do you have direct access to the DB for setting it up? What format is the DB sending you back the data? As @Becquerel said, a UNIX timestamp is the best approach https://currentmillis.com/standard/specification/client-centric-time/ let the client handle the final format.
That's not a postgres data type
DateTime2
is MSSQL type, IIRCYup