C
C#3y 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
Becquerel3y 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
kopuoOP3y ago
I'm using postgresql with datetime2 column type
BlueJayBird
BlueJayBird3y 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
reacher3y ago
That's not a postgres data type
Angius
Angius3y ago
DateTime2 is MSSQL type, IIRC
reacher
reacher3y ago
Yup
Want results from more Discord servers?
Add your server