Get day of the week

Discussion in 'JavaScript' started by xlcho, Jun 19, 2008.

  1. #1
    How to get the day of the week in JS. I want something similar to PHP's date('w'), but i've not found anything like that...
    Any help will be highly appreciated :)
     
    xlcho, Jun 19, 2008 IP
  2. koolman

    koolman Peon

    Messages:
    76
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You use getDay() function
    The return value is from 0 to 6
    0->Sunday
    1->Monday
    ...
    6->Saturday

    If you need to return string like "Mon" rather than value 1 of getDay(), you need to make a array:
    weekdays = new Array("Sun","Mon","Tue","Wed,"Thu","Fri","Sat");

    Then get string value from weekdays[d.getDay()]
     
    koolman, Jun 19, 2008 IP
  3. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yep, I found it. Thank you anyway koolman :)
    I was stuck on calculating stuff using getDate() and apparently i've missed getDay() several times when reading the documentation...
     
    xlcho, Jun 19, 2008 IP