[Gambas-user] Format function changes date value

George gambas at geodosch.com
Sat May 19 19:48:17 CEST 2018


(This was originally posted in gambas-user at lists.sourceforge.net
I've since seen that list has been deprecated, so I'm reposting the
pertinent issues here)

When using the Format function to format a date, the date gets offset by 1
day.  Here's an example:

  Dim zTestDate As String
  Dim zTestResult As String
  zTestDate = "5/4/2018"
  zTestResult = Format(CDate(zTestDate), "mm/dd/yy ddd")
  Debug "Test date: " & zTestDate & " Formatted: " & zTestResult

Result: Test date: 5/4/2018 Formatted: 05/03/18 Thu

This seems to have started since the last update was applied.

>T Lee Davidson <t.lee.davidson at gmail.com>
>
>CDate uses UTC and, without the time information in the string, it would
store midnight. Format uses local time.
>
>So, anyone in a time zone behind UTC will get the previous day printed.
Try this format string:
>zTestResult = Format(CDate(zTestDate), "mm/dd/yy hh:nn ddd")
>
>Does the difference in hours match your timezone offset?

That is definitely part of the issue.  My local time is GMT-04, and here's
what I get when specifying the time in my test:

Test date: 5/4/2018 03:59:00 Formatted: 05/03/18 Thu
Test date: 5/4/2018 04:00:00 Formatted: 05/04/18 Fri

However, if I look at time in the results, the difference isn't exactly the
offset:
Test date: 5/4/2018 03:59:00 Formatted: 05/03/18 23:05:00  Difference:
4:54:00
Test date: 5/4/2018 04:00:00 Formatted: 05/04/18 00:05:00  Difference:
3:55:00
Test date: 5/4/2018 00:00:00 Formatted: 05/03/18 20:05:00  Difference:
3:55:00

The offset isn't an even number of hours. What's also odd is that this was
never a problem before about a week ago.  This code is many years old, and
the problem suddenly began occurring with compiled code.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180519/2f8f355f/attachment.html>


More information about the User mailing list