PDA

View Full Version : date skipping


saltzmanjoelh
03-20-2009, 01:43 AM
Why does the date skip when I try to update it by 1, continuously?


var currentDate:Date = new Date();
var date:int = (currentDate.date + 1);
currentDate.date = date;



var currentDate:Date = new Date();
var date:int = (currentDate.date + 1);
currentDate.setDate = date;


If I continue to do this in Feb from 16th for 10 times I get
16, 17, 18, 20, 21, 22, 24, 25, 26, 28

mastermind81
03-20-2009, 11:57 AM
It is recommended in the Adobe docs to do arithmetics with dates by converting the values into milliseconds so use this snipt

var currentDate:Date = new Date();
const millisecondsPerDay:int = 1000 * 60 * 60 * 24;
currentDate.setTime(currentDate.getTime() + millisecondsPerDay);

saltzmanjoelh
03-26-2009, 12:45 AM
That still doesnt work for me



var millisecondsPerDay:int = 1000 * 60 * 60 * 24;
_currentDate.setTime(_currentDate.getTime() + millisecondsPerDay);


Here is what 30 days looks like starting on feb 2, 2009:

2
3
4
6
7
8
10
11
12
14
15
16
18
19
20
22
23
24
26
27
28
2
3
4
6
7
8
10
11
12

saltzmanjoelh
03-26-2009, 12:53 AM
This works

_currentDate.setHours(24, 0, 0, 0);

wvxvw
03-26-2009, 12:58 AM
var currentDate:Date = new Date();
const millisecondsPerDay:Number = 1000 * 60 * 60 * 24;
for(var i:int; i < 30; i++)
{
currentDate.setTime(currentDate.getTime() + millisecondsPerDay);
trace(currentDate.date);
}
int isn't capable of holding numeric representation of the date as it's max value is only 0x7fffffff, which is apparently not enough to represent date in milliseconds.

saltzmanjoelh
03-26-2009, 01:00 AM
good catch! thanks for that.