[Gambas-user] Return Value of Date() function

Tobias Boege taboege at ...626...
Mon Sep 28 10:59:30 CEST 2015


On Mon, 28 Sep 2015, Rolf-Werner Eilert wrote:
> 
> Am 25.09.2015 14:44, schrieb Tobias Boege:
> > On Fri, 25 Sep 2015, emanuele sottocorno wrote:
> >> As stated in the wiki the Date Function should return a date without its
> >> time component.
> >> http://gambaswiki.org/wiki/cat/time
> >>
> >> But: Print Date(Now) ---> 25/09/2015 00:00:00
> >>
> >> Is it by design?
> >>
> > The Date() function returns data of type Date. This datatype is designed to
> > hold date and time information, so there is no way to return a date in a
> > Date value without a time component.
> >
> > You should think of the Date() function as *stripping* the time information
> > from a Date value, by replacing the time information with zeros.
> >
> > Regards,
> > Tobi
> >
> So the correct way to handle this if I wish to process the date would be 
> either to use the built-in functions day(), month(), year() and then 
> connecting them to whatever, or make a string out of it to be used. Right?
> 
> myDateString = String.Left(CStr(Date(Now)),  10)
> 
> The same way if you do need the time information (e. g. for making a 
> file name by date+time), but then it's easier to use Mid or String.Mid 
> to peek the values and concatenate them to form a file name the way you 
> need it.
> 

I think you could do that, but I would recommend

  Format$(Now, gb.ShortDate)

if you just want to display the date. Note that the Date() function is not
needed there. Because of localisation, the return value of the above call
is useful for display but not for further processing. The Date datatype
would be ideal for further processing, so that you should never need to
resort to String.Left() and co. :-)

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the User mailing list