[Gambas-user] Format function changes date value

ML d4t4full at gmail.com
Thu Jun 7 20:34:49 CEST 2018


On 07/06/18 15:11, Gianluigi wrote:
> 2018-06-07 17:12 GMT+02:00 Benoît Minisini <g4mba5 at gmail.com
> <mailto:g4mba5 at gmail.com>>:
>
>     Le 07/06/2018 à 16:51, Gianluigi a écrit :
>
>         I wrote it even if I imagined it was wrong (it works here),
>         I'm sorry.
>         It's useless, with the dates I still do not understand anything.
>         These coming days, I will try to write a my wiki to and submit
>         it to your judgment.
>         Regards
>         Gianluigi
>
>
>     I try to explain again:
>     1) Date & times are internally represented in UTC date. See them
>     as a number of days since an absolute instant in the past. You can
>     get this number with CFloat(AnyDate). The integer part is the
>     number of days, the fractional part is the part of the day (the
>     precision is the millisecond).
>     2) Each time you read or you write a date & time as a string, you
>     *must* know the timezone associated with the string
>     representation. *But* this timezone is implicit, as it is not
>     written inside the string representation (something that I should
>     add to Gambas).
>     In other words, "2018/6/7" *cannot* represent an absolute time
>     instant. It depends on the implicit timezone.
>     3) So, all Gambas functions that deal with date & time as a string
>     *must* assume a timezone. Some functions assume UTC timezone, and
>     others assume local timezone. Normally, all documentation pages on
>     the wiki says which one is used.
>     Is it clearer now?
>     -- 
>     Benoît Minisini
>
>
> Hi Benoit,
> sorry for the delay, I had to go out.
> The difference between local and UTC is clear to me.
> I find it difficult to memorize, to fix well in my mind, to fully
> understand the translation into the string.
> Suppose we have a CUsers class where I store user data including the
> date of birth.
> Suppose I use this class as an array:
>    hObj = New CUsers (iId, sName, sSurName, dDate, ...)
>    $hGlobalObject.Add(hObj)
> If I have to save the date in an ini file like Settings and I want to
> be sure that I do not have problems, how do I translate the date to be
> saved into a string, and then how can I re-translate it into a date
> format from ini?
> So I'm in confusion, I would use CStr and then CDate to stay in UTC
> and then display the dates with Format.
> I know I'm an idiot, and I'll continue to use a database...
> Regards
> Gianluigi

I'd break the date down to day, month, year, and store them as 3
separate data units.
Then, when retrieving, read the three separate data items and use:

  Dim userBirthday As Date = Date(savedYear, savedMonth, savedDay)

So userBirthday will be a Date with the proper value... If I inderstood
it correctly, that is!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20180607/43f1a913/attachment-0001.html>


More information about the User mailing list