A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: turning dates into numbers of the year

  1. #1
    ReMember gobbles's Avatar
    Join Date
    Nov 2002
    Location
    Denmark
    Posts
    983

    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
    http://www.rickigregersen.com ...finally a blog!

    Your damned if you do...but your particually damned if you don´t

  2. #2
    Senior Member
    Join Date
    Feb 2004
    Location
    California
    Posts
    174
    need to worry about leap years?

  3. #3
    ReMember gobbles's Avatar
    Join Date
    Nov 2002
    Location
    Denmark
    Posts
    983
    won't be a problem....
    http://www.rickigregersen.com ...finally a blog!

    Your damned if you do...but your particually damned if you don´t

  4. #4
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    // 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;

  5. #5
    Junior Member
    Join Date
    Apr 2006
    Posts
    7
    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.

  6. #6
    ReMember gobbles's Avatar
    Join Date
    Nov 2002
    Location
    Denmark
    Posts
    983
    Look at serpicho.com ... i think.. or net...he has made all kinds of calendar tutorials..
    http://www.rickigregersen.com ...finally a blog!

    Your damned if you do...but your particually damned if you don´t

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center