-
ReMember
turning dates into numbers of the year
hi
This late nigth Im sorta stuck on the getTime milliseconds thing wich Im not sure I fully understand...
I need to convert a date array like this..
array(1-1-2004 , 1-2-2004 , 12-31-2004)
into the number that date has in the year like this
array(1 , 2 , 365)
Im really lost...
thanks everybody
-
need to worry about leap years?
-
ReMember
-
Senior Member
// How to convert July 17th to a number (1-365)
year = 2004;
mon = 7;
day = 17;
// Get date for January 1 of the same year
// since that's where we're counting from
d1 = new Date(year,1-1,1);
// Get date for July 17
d2 = new Date(year ,mon-1,day);
// Get the difference in milliseconds
diff = d2.getTime() - d1.getTime();
// Divide by length of day (in milliseconds)
kLengthOfDay = 1000*60*60*24;
diff = diff / kLengthOfDay;
// Add 1
diff += 1;
// That's it.
numberOfDays = diff;
-
This little script has been super helpful. I'm trying to write one that works in reverse: given the day of the year what is the date? I'm not quite getting it. Any suggestions would be appreciated. Awesome.
-
ReMember
Look at serpicho.com ... i think.. or net...he has made all kinds of calendar tutorials..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|