[Gambas-user] problem with the CDate function

Mayost Sharon sharon at 455.co.il
Mon May 7 00:47:09 CEST 2018



---------- Original Message -----------
From: Benoît Minisini <g4mba5 at gmail.com>
To: Gambas Mailing List <user at lists.gambas-basic.org>
Sent: Wed, 2 May 2018 15:46:44 +0200
Subject: Re: [Gambas-user] problem with the CDate function

> Le 02/05/2018 à 15:38, Gianluigi a écrit :
> > 
> > 
> > 2018-05-02 15:18 GMT+02:00 Mayost Sharon <sharon at 455.co.il 
> > <mailto:sharon at 455.co.il>>:
> > 
> >     Hello
> > 
> >     Operating system: Fedora 27 64 BIT
> >     Gambas 3.10.0
> > 
> >     I have a problem with the CDate function when I run the example that
> >     appears in this
> >     documentation:
> > 
> >     It takes me back one day
> > 
> >     I run:
> > 
> > 
> >     Print CDate ("09/06/1972 01:45:12")
> > 
> >     And it returns to me:
> > 
> >     09/05/1972 22:45:12
> > 
> > 
> > You must use Date and not CDate which locates the UTC date [0].
> > 
> > Regards
> > Gianluigi
> > [0] https://en.wikipedia.org/wiki/Coordinated_Universal_Time
> >
> 
> No, it's not the problem.
> 
> It's just that people must understand that CDate() interprets its 
> argument as an UTC date, and that Str() (hence Print) converts a date 
> into a local representation.
> 
> So if you use CDate(), you must use CStr() to go back to the original 
> string. Otherwise, use Val() and Str().
> 
> See the documentation about these functions. I think some non-american 
> examples should be added to make things clearer.
> 
> Regards,
> 
> -- 
> Benoît Minisini
> 
> --------------------------------------------------
> 
> This is the Gambas Mailing List:
> https://lists.gambas-basic.org/listinfo/user
> 
> Search the list:
> https://lists.gambas-basic.org/cgi-bin/search.cgi
> 
> Hosted by https://www.hostsharing.net
------- End of Original Message -------


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
   Print "Date() Is > str_data"
  Else
   Print "Date() Is < Or = str_date"
  Endif
 
 Print Date()
 Print Date(str_date)

End

I get this output:
Date() Is > str_data
05/07/2018 00:00:00
05/06/2018 00:00:00


it seems strange that the current date today is:
Month: 05
Day: 07
Year: 2018

Then the value of str_date should equal the value of Date ()

What should I fix in the code to make it good

Thank you



More information about the User mailing list