[Gambas-user] Format function changes date value

George gambas at geodosch.com
Wed Jun 6 23:35:48 CEST 2018


I'm not sure why the previous, more consistent behavior, was considered a
bug, and why it's deemed better now that it's 'fixed', and different date
functions behave differently, and are incompatible with each other.

I have an application that makes extensive use of dates and date
calculations, which has worked just fine for years.  But now the bug fix
has seriously broken things.  I started to kludge some of the code to make
it work, but I could see I was heading down a rat-hole.  So in the end I
migrated it to .NET instead.

Just my $0.02


On Sat, May 19, 2018 at 2:43 PM, T Lee Davidson <t.lee.davidson at gmail.com>
wrote:

> I don't get that 5 minute anomaly. With three blocks each defining
> zTestDate through Debug (Print), I get:
> Main.Main.9: Test date: 5/4/2018 Formatted: 05/03/18 20:00 Thu
> Main.Main.12: Test date: 5/4/2018 03:59:00 Formatted: 05/03/18 23:59 Thu
> Main.Main.15: Test date: 5/4/2018 04:00:00 Formatted: 05/04/18 00:00 Fri
>
>
> On 05/19/2018 01:48 PM, George wrote:
> > (This was originally posted in gambas-user at lists.sourceforge.net
> <mailto: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 <mailto: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.
> >
> >
> >
> >
> > ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
> >
>
> --
> Lee
>
> ----[ Gambas mailing-list is hosted by https://www.hostsharing.net ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gambas-basic.org/pipermail/user/attachments/20180606/9532b810/attachment.html>


More information about the User mailing list