[Gambas-user] problem with the CDate function

Benoît Minisini g4mba5 at gmail.com
Tue May 8 14:09:54 CEST 2018


Le 07/05/2018 à 00:47, Mayost Sharon a écrit :
> 
> Sorry
> I do not understand
> 
> If I run this code:
> 
> Public Sub Main()
> 
>   Dim str_date As String
>   
>   str_date = "05/07/2018 00:00:00"
> 
>   
>   If Date() > Date(str_date) Then

Date() does not take a String, but a Date. So what you are writing is 
equivalent to:

    If Date(Now) > Date(CStr(str_date))

So your string 'str_date' is assumed to be an UTC date.

As Date() extracts the date in the current time zone, Date(Now) may be 
different from Date("05/07/2018 00:00:00") if you are not in the UTC 
time zone.

1) Each time you have a date as a string, you must ask yourself what the 
timezone is.

2) Each time there is a conversion between Date and String, you must ask 
yourself which timezone is used.

Regards,

-- 
Benoît Minisini


More information about the User mailing list