[Gambas-user] CDate Documentation

BB adamnt42 at gmail.com
Tue Nov 15 07:12:35 CET 2022


On 15/11/22 2:30 pm, Jussi Lahtinen wrote:
>
> Dim hDate1 As Date = CDate("12/24/2024 12:00") ''<-- here it is given 
> as UTC
> Dim hDate2 As Date = Val("12/24/2024 12:00") ''<-- here it is given as 
> local time
>
> Print CStr(hDate1);; Str(hDate1) ''internal presentation & localized 
> presentation accordingly
> Print CStr(hDate2);; Str(hDate2)
>
>
> Jussi

I gave that a try (albeit, slightly differently) over several timezones 
and everything worked as expected?

   Dim hDate1 As Date = CDate("12/24/2024 12:00")  ''<-- here it is assumed that the string is UTC"
   Dim hDate2 As Date = Val("24/12/2024 12:00")    ''<-- here it is assumed to be a local time

   ' So whats the values?
   Print Env["TZ"], CFloat(hdate1), CFloat(hDate2)                                      '' "As expected, they are different"
   
   ' Now do some conversions...
   ' CStr(Date) gives the representation of the date in UTC TZ
   ' Str(Date) gives the representation of the date in the "current" TZ i.e. Env("TZ")
   ' Printing the raw date is the same as Str(Date)
   ' Printing the Formatted raw time gives the converted time and the right TZ
   Print CStr(hDate1), Str(hDate1), hDate1, "!", Format(hDate1, "hh:nn t")   '' "All 4 outputs are as expected"
   Print CStr(hDate2), Str(hDate2), hDate2, "!", Format(hDate2, "hh:nn t")   '' "All 4 ouputs are as expected"
   Print CStr(CDate(CFloat(hDate1)))                                         '' "UTC As expected"
   Print (CDate(CFloat(hDate1)))                                             '' "Local As expected"
   Print CStr(CDate(CStr(hDate1)))                                           '' "UTC As expected"

Sample output:

HST     2492773.5       2492773.91666667
12/24/2024 12:00:00     24/12/2024 02:00:00     24/12/2024 02:00:00     !       02:00 HST
12/24/2024 22:00:00     24/12/2024 12:00:00     24/12/2024 12:00:00     !       12:00 HST
12/24/2024 12:00:00
24/12/2024 02:00:00
12/24/2024 12:00:00

b

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20221115/e4a27ca5/attachment.htm>


More information about the User mailing list