getDate() and setDate()

Hi,

I’ve seen a strange situation. See the following coding:

	var _time = new Date(registration_time_start)
	_time.setFullYear(registration_date.getFullYear())	
	_time.setMonth(registration_date.getMonth())
	_time.setDate(registration_date.getDate() + 1)
	_time.setMilliseconds(0);
	
	registration_time_start = _time;

I have 2 fields; 1 field for date registration (registration_date, with format DD/MM/YYYY) and 1 field for time registration (registration_time_start, with format HH:mm)

My field registration_date contains 30/07/2009
My field registration_time_start contains initially 01/01/1970 08:00 (because I use format HH:mm Servoy defaults the date to 01/01/1970)

So far, so good

The above coding shows that I take the dateparts of registration_date and put this in the datepart of registration_time_start

What I don’t understand is that I have to use:

_time.setDate(registration_date.getDate() + 1)

instead of

_time.setDate(registration_date.getDate())

Is there an explanation for that? If I use _time.setDate(registration_date.getDate()) the datepart in registration_time_start contains 29/07/2009

It doesn’t seem very logic to me, that when I put a getDate() into a setDate() that I have to add 1 day.

Can anyone explain that?

Martin

It works for me as expected, so without the + 1.

Are you sure your dates are in the same timezone? Does it make a difference if you use .getUTCDate() and .setUTCDate()?

Hi Joas,

No difference between getDate and getUTCDate(); Never used UTC-functions; what does it do?

	application.output('Time=' + registration_time_start)
	application.output('Date=' + registration_date)
	application.output('getDate()=' + registration_date.getDate())	
	application.output('getUTCDate()=' + registration_date.getUTCDate())

Result:
Time=Thu Jul 30 08:00:00 CEST 2009
Date=Thu Jul 30 00:00:00 CEST 2009
getDate()=29
getUTCDate()=29

I’m working with Servoy 4.1.3

Martin

martinh:
Never used UTC-functions; what does it do?

They use Universal Time aka GMT, so they “ignore” the timezone.

I’m not sure what causes your problem. Are both values saved correctly to the db?

On a side note, why do you use two values anyway? Why don’t you put the same field on the form, once with format DD/MM/yyyy and once with HH:mm?

Joas:
I’m not sure what causes your problem. Are both values saved correctly to the db?

They are saved in the database as you see them in debugger. So as 29/07/2009 without the +1 and as 30/07/2009 with the +1

Joas:
On a side note, why do you use two values anyway? Why don’t you put the same field on the form, once with format DD/MM/yyyy and once with HH:mm?

Because it is a time registration system where 1 date is selected; A starting date; ending date and probably also start/end of pause;
So I don’t want the date to be repeated in each time field