Picture of Marvin 5515
Registered 3 years 273 days
Marvin 5515 Monday, 12 July 2021, 02:34 PM
JS SDK database date type
Hello,

does anyone know how the sdk handles dates in the database?
I tried to add a datefield into the database, but unfortunately it doesnt pick up my used format.

After i add data to the database, it looks like that:

{
"id": 7,
"username": "marvin",
"date": 2021,
}

but im sending it in this format:

{
"id": 7,
"username": "marvin",
"date": 2021-07-12,
}

Would be glad if anyone could help me.

Best Regards

Picture of Daniel Deterding (innovaphone)
Moderator Registered 15 years 121 days
Daniel Deterding (innovaphone) Monday, 12 July 2021, 03:14 PM
Re: JS SDK database date type
Hi Marvin,

we do not use date formats of the database at all. Instead we use the BIGINT (ulong64) datatype to store a unix timestamp in milliseconds since 1970 UTC.

In Javascript, you can simply convert such a number to a Date object:
var date = new Date(BIGINT);

And you get the value back like:
date.getTime();

In server side C++, you can use our ITime interface to work with such timestamp and there are also methods to convert this into readable strings:
https://sdk.innovaphone.com/13r2/sdk/common/interface/time.htm#ITime

or to work with timezones:
https://sdk.innovaphone.com/13r2/sdk/common/interface/timezone.htm

Greetings,
Daniel
Picture of Marvin 5515
Registered 3 years 273 days
Marvin 5515 Wednesday, 14 July 2021, 11:52 AM
Re: JS SDK database date type
Hi Daniel,

I'm trying to convert '2021-07-14' to a date like this:


function toTimestamp(year,month,day,hour,minute,second){ var datum = new Date(Date.UTC(year,month-1,day,0,0,0)); log('datum: ', datum.getTime()/1000); return datum.getTime()/1000; } 
Then I call the function E.g.:
toTimestamp(2021, 07, 14);
and get something like this: 1626220800

When I try to add the value to the database the following error appears:
07-14 09:31:12.003 demoapp@trizwo.de PostgreSQLDatabase(0125a880,01259b48)::LastCommandFailed (22008):ERROR: date/time field value out of range: "1626220800" LINE 1: ..., 'demo', '162622080... ^ 
HINT: Perhaps you need a different "datestyle" setting.

I tried to set datestyle to epoch, without success.

How do I add the value to the db?

Best Regards

Marvin

Picture of Daniel Deterding (innovaphone)
Moderator Registered 15 years 121 days
Daniel Deterding (innovaphone) Wednesday, 14 July 2021, 12:17 PM
Re: JS SDK database date type
Hi Marvin,

you must use BIGINT as column datatype.
Basically the database doesn't know at all that this is a column which contains a date/timestamp in this case.

Greetings,
Daniel
← You can define your color theme preference here