Subject Re: date class
From Gaetano D. <gaetanoddRemoveThis@andThatHotmail.com>
Date Thu, 17 Jun 2021 05:20:22 +1000
Newsgroups dbase.getting-started

On 16/06/2021 04:59, Mustansir Ghor wrote:
> Dear All
>
> The date class has a method oref.setyear(ExpN) which is suppose to change date object with same date and month but ExpN year. But it return GMT character date.
>
> Is there another way to it
>
> Best Regards
> Mustansir
>
Hi Mustansir,

To check this further, please show us how you create the date object and
how you set the initial value for the object. Also, I can you show how
you get the GMT string - the date being a date, it can only be converted
to a string with a function or method like oRef.toString(). If the date
object is valid, there is no reason setYTear() should not work.

d=new date()
d.setYear(2021)
?d // correctly returns 17/6/2021
d.setYear(2022)
?d // correctly returns 17/6/2022

One known problem with the date object is that it assumes MDY date
structure, and this can generate unexpected results (though not a GMT
string). Example (with date set to DMY):

d=new date("15/1/2021")
?d.tostring() // correctly returns Fri Jan 15 00:00:00 E. Australia
Standard Time 2021, because 15 is not a valid month, so dBase doesn't
use MDY but falls back to DMY
d=new date("1/12/2021") // being 1st December 2021
?d.tostring() //incorrectly returns Tue Jan 12 00:00:00 E. Australia
Standard Time 2021, because 12 is a valid MDY month value, so that is
the first choice in the logic

For the same reason, you cannot use a date field or a timestamp field in
a rowset to populate the date object. It is not safe to do something like:

d= new date(oQuery.rowset.fields["myDate"].value) // this will produce
incorrect results the same way as in the above example

--

Gaetano.