Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

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)
  • Author
    Posts
  • #177709
    TWG
    Participant

    Okay. 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;
                    }
                });
    
    #177752
    TWG
    Participant

    @Soronbe,

    Thanks 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.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.