0

I am filling up an object array, first I read an existing object as date (eg. 2015-12-03) and then assign the day part (03) to a variable. I want to change the number to "Thursday", depending on the real date format, not the actual date. And I want to do the same with the month format too.

   $.getJSON("data/output.json", function (data2) {
                        $.each(data2.result, function(key, value){
                        var date =  (JSON.stringify(data2.result[key].start_date));
                        day = date.slice(9, -1);
                        day.
                        data2.result[key].day=day;
                        /*month = date.slice(6, -4);
                        var monthstring = {"month": month};
                        data2.result[key].push(monthstring);*/
                    });
                        view2 = data2;
                        console.log(view2);
                    });
mostar
  • 4,723
  • 2
  • 28
  • 45
SJWimmer87
  • 73
  • 3
  • 7
  • No it is not, I have many dates in a json file, Im not interested in the actual date. – SJWimmer87 Dec 03 '15 at 12:15
  • 1
    Is the same. You have an string, you must to convert to date and apply to get the value you want. It's really a duplicate. – Marcos Pérez Gude Dec 03 '15 at 12:18
  • Yep it is, create a date and then use the `.getDay()` and `.getMonth()` – Pete Dec 03 '15 at 12:18
  • However, if this is more complex than you expected, you can use the Moment.js library that handles and manipulates dates easily, without deeply knowledge of date handling. http://momentjs.com/ – Marcos Pérez Gude Dec 03 '15 at 12:20
  • I can not find the user manual for moment.js. – SJWimmer87 Dec 03 '15 at 12:32
  • Can you clarify what you are trying to do please? Your title says "get weekday" but your question says "change to Thursday" (seems a bit specific...). ie add some expected input gives expected output examples – freedomn-m Dec 03 '15 at 12:33
  • Try that big link at the top right that says "docs": http://momentjs.com/docs/ – freedomn-m Dec 03 '15 at 12:34
  • I can't see how the duplicate link *doesn't* match your scenario with the *smallest* change. Instead of `date = new Date()` use `date = new Date(JSON.stringify(data2.result[key].start_date)).slice(9, -1))` – freedomn-m Dec 03 '15 at 12:36
  • Thank you, sorry for the repost. – SJWimmer87 Dec 04 '15 at 07:19

0 Answers0