Return day from date (javascript)?

Ok, I know this isn’t a Rails problem, but if you could help me out
that’d be brill.

I’ve used JavaScript to create a new Date object containing a date of my
choice…

mydate = new Date(“11/24/2007”);
//going with Javascript’s mm/dd/yyyy format

now this is good, what i want to do now is put in an integer variable
the number for the day, in this case 24

Now if i use JavaScript’s getDay() function it will return the numeric
day of the week for that day (e.g. 2 for Monday).

what i really want is the numeric day for that date, aka 24

Looked around and Javascript doesn’t have a .day element.

Any ideas how I can accomplish this in JavaScript ?

Appreciate this, really,

John.

This works, it’s hackish but it works.

date = new Date(“11/24/2007”);
date.toDateString().split(" ")[2];

Make sure you have the space between the " " in the split function

Merry xmas,
Cam

On Dec 24, 8:35 am, John G. [email protected]

On Dec 23, 2007, at 3:35 PM, John G. wrote:

now this is good, what i want to do now is put in an integer variable
the number for the day, in this case 24

Now if i use JavaScript’s getDay() function it will return the numeric
day of the week for that day (e.g. 2 for Monday).

what i really want is the numeric day for that date, aka 24

Oh, you were so close!

getDate()

Phillip

ugh…

i feel so stupid :wink:

thank philip,

have a happy christmas

John.

Sorry, I forgot to add a nice reference URL:

http://www.w3schools.com/jsref/jsref_obj_date.asp

Peace,
Phillip

Can’t you do:

myDate = getDate(“11/24/2007”);
MyDate.day();

Or am I dreaming?

On Dec 24, 2007 8:56 AM, Phillip K. [email protected] wrote:


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

On Dec 23, 2007, at 4:49 PM, Ryan B. wrote:

Can’t you do:

myDate = getDate(“11/24/2007”);
MyDate.day();

Or am I dreaming?

day() is not a function. getDay() returns the ordinal day of week.
getDate() returns the day of the month.

Peace,
Phillip

So that’s what I get for it being a Monday, Christmas Eve no less.
remembers to consult web before suggesting things

:wink:

you guy’s are the best!

if you ever get near my part of the world, drop me a line, beer’s most
definitely on me,

have a smashing christmas!

John.

Ah I totally missed that getDate() funtion as well. That’ll teach me
for not reading more closely…

Glad it worked out for you.

Cam

Define “part of the world”

On Dec 24, 2007 8:47 PM, John G.
[email protected]
wrote:

John.

Posted via http://www.ruby-forum.com/.


Ryan B.
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.

getDate()

What a poorly named function!

///ark

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs