C
C#2y ago
kopuo

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
Becquerel
Becquerel2y ago
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
kopuo
kopuo2y ago
I'm using postgresql with datetime2 column type
BlueJayBird
BlueJayBird2y ago
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.
reacher
reacher2y ago
That's not a postgres data type
Angius
Angius2y ago
DateTime2 is MSSQL type, IIRC
reacher
reacher2y ago
Yup