Convert DB date

Hello,

i need to convert a bigInt from a a database (see link) -> fromDT to a date object and then check if the current date is newer than the one in the db.

But i do not know how to convert it into a date…

database

Marco

The BIGINT, what is it? I.e. is it the number of seconds since a particular start date?

well it all depends on what that BigInt represents… is it totalseconds? days? hours? and what base date? could it be a Unix value?

its a unix timestamp…

1549234800 = GMT: Sunday, 3. February 2019 23:00:00

THe number of seconds since 1st January 1970 then?

https://www.unixtimestamp.com/index.php

Xojo.Core.Date.Constructor(secondsFrom1970 As Double, timezone As TimeZone)

If you want to stick with the classic framework, something like this:

static d1970 as new Date( 1970, 1, 1, 0, 0, 0 )

dim d as new Date
d.TotalSeconds = theValue + d1970.TotalSeconds

[quote=431206:@Kem Tekinay]If you want to stick with the classic framework, something like this:

[code]
static d1970 as new Date( 1970, 1, 1, 0, 0, 0 )

dim d as new Date
d.TotalSeconds = theValue + d1970.TotalSeconds
[/code][/quote]
that isn’t right… as it would be off by the # of seconds between 1970 and 1904

Isn’t d1970.TotalSeconds the # of seconds between 1904 and 1970?

Here is a blog post I made using the “New” (old?) framework in adding days to a starting point. It’d only take a small adjustment to get it working with seconds instead of “days”. Xojo Date Math I hope this helps!

no… current framework use 1904 as “zero”, d1970 uses 1970 as “zero”

Static d1970 As New date(1970,1,1,0,0,0) MsgBox d1970.TotalSeconds.ToText
is not “zero” it shows: 2082844800.000000

I checked it before I posted.

Here’s what I use.

[code]Public Function UnixToDate(UnixTime As Double) as Date
// NOTE: THIS ROUTINE USES THE OLD FRAMEWORK DATE CLASS
// NOTE 2: The UnixTime value may or may not be “localized” by the service.
// Thus, the Date returned may need adjusting for UTC offset to local time zone.

// time value is in UNIX time (totalseconds) from 01/01/1970
// conversion is to set a Date object to 01/01/1970 and
// add the time value to the Date object’s totalseconds.
Dim tme As Double
Dim dte As New date(1970, 1, 1)

tme = UnixTime
tme = dte.TotalSeconds + tme
dte.TotalSeconds = tme

Return dte

End Function[/code]