#1 2021-09-23 23:22:05

Junior/RO
Member
Registered: 2011-05-13
Posts: 201

Convert TSQLHttpClient.ServerTimeStamp to local time

I need to convert ServerTimeStamp, UTC time, to local time.

Any hints?

Offline

#2 2021-09-24 00:12:34

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: Convert TSQLHttpClient.ServerTimeStamp to local time

I believe you can use TSynTimezone for this:
localtime =  UtcToLocal(TimeLogToDateTime(Server.ServerTimeStamp), 'Your Timezone');

See: https://synopse.info/forum/viewtopic.php?id=5976

But docs says:

/// the current Date and Time, as retrieved from the server
// - note that this value is the DB_SERVERTIME[] constant SQL value, so
// will most likely return a local time, not an UTC time ...
property ServerTimestamp: TTimeLog

Offline

#3 2021-09-24 03:09:59

Junior/RO
Member
Registered: 2011-05-13
Posts: 201

Re: Convert TSQLHttpClient.ServerTimeStamp to local time

macfly wrote:

I believe you can use TSynTimezone for this:
localtime =  UtcToLocal(TimeLogToDateTime(Server.ServerTimeStamp), 'Your Timezone');

Thank you.


But docs says:
property ServerTimestamp: TTimeLog

That's different from the source code comments. In mORMot.pas, TSQLRest.ServerTimeStamp says

    /// the current UTC Date and Time, as retrieved from the server
    // - this property will return the timestamp as TTimeLog / Int64

Offline

#4 2021-09-24 07:08:31

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,187
Website

Re: Convert TSQLHttpClient.ServerTimeStamp to local time

I don't see what is the difference.
It says it is TTimeLog encoded, which is the case.

Online

#5 2021-09-24 12:31:00

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: Convert TSQLHttpClient.ServerTimeStamp to local time

Hi ab,
We are referring to that in one part of the documents it says that it returns UTC and in another the local time.

mormot1
SynDB.pas

/// the current Date and Time, as retrieved from the server
    // - note that this value is the DB_SERVERTIME[] constant SQL value, so
    // will most likely return a local time, not an UTC time

mORMot.pas

/// the current UTC Date and Time, as retrieved from the server
    // - this property will return the timestamp as TTimeLog / Int64


mormot2
motmot.db.sql.pas

/// the current Date and Time, as retrieved from the server
    // - note that this value is the DB_SERVERTIME[] constant SQL value, so
    // will most likely return a local time, not an UTC time

Offline

#6 2021-09-24 14:39:59

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 13,187
Website

Re: Convert TSQLHttpClient.ServerTimeStamp to local time

Those are not the same values.
The one from SynDB or motmot.db.sql.pas is not the one from TSQLRest instances.

The first comes from the DB itself, from executing a SQL statement depending on the engine. It may or may not be the local time. Its purpose is to have the same time as may have been stored in regular SQL statements.

The TSQLRest time is always the UTC REST server time as returned by the OS. It is the time used by the ORM to fill created/modified timestamps fields.

Online

#7 2021-09-24 16:18:39

macfly
Member
From: Brasil
Registered: 2016-08-20
Posts: 374

Re: Convert TSQLHttpClient.ServerTimeStamp to local time

Thanks for clarification

Offline

Board footer

Powered by FluxBB