[Gambas-user] Format function changes date value

Benoît Minisini g4mba5 at gmail.com
Thu Jun 7 16:00:31 CEST 2018


Le 07/06/2018 à 15:52, George a écrit :
> This is what broke my code:
> Dim Dat1 As Date
>    Dat1 = "6/1/2018"

The problem is here. The automatic conversion is done by CStr(), i.e. it 
assumes that "6/1/2018" is UTC...

>    Message("Dat1: " & Dat1 & " Formatted: " & Format(Dat1, "mm/dd/yyyy"))

...but Format() prints the date in local timezone...

> 
> Result: Dat1: 06/01/2018  Formatted: 05/31/2018

...And so you may have a difference.

Each time you have a string converted to a date or the contrary, you 
must know which timezone Gambas assumes.

To convert a string in local date, you have to use Val("6/1/2018"), or, 
faster, Date(2018,1,6).

> 
> I stand corrected on the DateDiff issue; my code was not using it 
> because it's counting days based on a schedule of working/non-working 
> days.  Since I hadn't gotten past the 'Format' issue, I never dove into 
> that part of the code to see why it was breaking, other than seeing that 
> day calculations, which used to work, no longer did since the patch.
> 

For working / non-working days, I have written my own function (based on 
French days-off), but I didn't put it in Gambas yet.

-- 
Benoît Minisini


More information about the User mailing list