[Gambas-user] Best way converting dates into strings forth and back

Benoît Minisini g4mba5 at gmail.com
Fri Dec 10 22:46:43 CET 2021


Le 10/12/2021 à 21:36, Jussi Lahtinen a écrit :
>     Again, you are confusing date/time (which are absolute) with their
>     string representation (which are not).
> 
> 
> No.
> Consider this. If I store date 10.12.2021 22:27 in UTC right now 
> (winter), I will get: 12/10/2021 20:27 UTC.
> If I store *the same* date in UTC in *summer*, I will get: 12/10/2021 
> 19:27 UTC.

"12/10/2021 20:27 UTC" is different from "12/10/2021 19:27 UTC", so they 
are not the same date/time. This is why UTC has been designed, to get an 
absolute date/time representation.

If you store the same date/time in an UTC string representation, you 
will have the same string, otherwise it is not the same date/time.

When you use the expression "the same date in UTC", you show that you 
are confusing dates with their string representation.

My full explanation of how dates work in Gambas is at: 
https://gambaswiki.org/wiki/doc/date

I strongly suggest that you read it carefully.

If someone can explain Jussi his mistake better than me, or suggest 
enhancements to the previous wiki document, he is welcome.

@Rolf-Werner: if you want, instead of CStr(TheDate) <-> 
CDate(TheString), you can use CStr(CFloat(TheDate)) <-> 
CDate(CFloat(TheString)). That way, instead of storing the timestamp as 
an UTC date/time string, you store it as a floating point in its 
american string format, that represents the same timestamp as it is 
stored in memory by Gambas.

Regards,

-- 
Benoît Minisini


More information about the User mailing list