Home › Forums › JavaScript › Getting the day of the week from date in javascript
- This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
August 5, 2014 at 8:48 am #177709
TWG
ParticipantOkay. I’ve read articles online that say to just use the .getDate(); on a date and it will return 0 through 6 depending on what day of the week it is. My issue is that I’m reading a date from a database in the following format YYYY-MM-DD:00:00:00 . Every time I try to take that number and run the .getDate on it, it will not complete. The code below works fine until I try to get the day of the week.
$.each(data, function (index, calendar) { if( calendar.StartDate >= current_date && count < 6 ) { var today = new Date(); var date_holder = calendar.StartDate; var event_datetime = date_holder.split('T'); var event_dtholder = event_datetime[0]; var event_date = event_dtholder.split('-'); var event_date_holder = event_date[1] + "/" + event_date[2] + "/" + event_date[0]; var temp_date = event_date[0] + "-" + event_date[1] + "-" + event_date[2] + "T00:00:00"; console.log(today); var event_day_temp = Date.parse(date_holder); var event_day = event_day_temp.getDay(); console.log(event_day); $holder = "
"; $(".events").append($holder); $holder = ""; count += 1; } });" + month[event_date[1] - 1] + "" + event_date[2] + "August 5, 2014 at 11:24 am #177752TWG
ParticipantThanks for the reply. I actually just figure out my problem about 10 minutes ago. I needed to do the following:
var day_temp = new Date("January 10, 1992");
Thanks for the reply though. I didn’t even think about the console.log until after I wrote this. Newbie mistake, oops.
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- The forum ‘JavaScript’ is closed to new topics and replies.