[Gambas-user] Question about date conversion in Gambas v2

Benoît Minisini gambas at ...1...
Mon Sep 27 20:44:42 CEST 2010


> Hi Benoit,
> 
> I have just a question about the possibility to convert in Gambas v2 a
> variable in format Date to a value of this date in number of seconds like
> in Unix command ?
> 
> In my projet i need to use date value in number of seconds and not in
> standard format as for example this one: not    26-09-2010 17:08:00   but 
>    in seconds  since 1970-01-01 00:00:00  =>  1285513680  seconds
> 
> I just want to know if it possible or not in Gambas v2 otherwise I will
> continue to use the Unix command 'date' ?
> 
> Thank in advance,
> 
> Olivier Cruilles
> Mail: linuxos at ...1896...
> 

Dates are internally stored as a number of seconds and microseconds from a 
Gambas epoch (which is not the Unix epoch), in GMT. 

When converted to Float, you get a number of days as integer part, and the 
rest as decimal part.

So, if you need a unix timestamp, i.e. a number of seconds since epoch, you 
just have to do that:

Print Int((CFloat(now) - CFloat(Date(1970, 1, 1))) * 86400)

Regards,

-- 
Benoît Minisini




More information about the User mailing list