Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery datepicker return weeknumber and day of week

Im trying to get the weeknumber and the name/shortcut of the weekday according to the chosen date through a JQuery calendar. Im not really proficient in JQuery so i can get the weeknumber, but i cant seem to get the name of the day with it.

Could anyone help me out?

  $('#datepicker').datepicker({
    onSelect: function (dateText, inst) {
        $('#weekNumber').val($.datepicker.iso8601Week(new Date(dateText)));
    }
});
like image 762
klekmek Avatar asked Apr 16 '15 14:04

klekmek


2 Answers

you have to get the date, than extract the name of the day from it:

      var date = $(this).datepicker('getDate');
      alert($.datepicker.formatDate('DD', date));

hope it helps!

edit: you can find the working fiddle here.

like image 56
rvandoni Avatar answered Sep 28 '22 17:09

rvandoni


You can add in your existing block to grab the day name, by using the format date syntax, found in the datepicker documentation, here: http://api.jqueryui.com/datepicker/#utility-formatDate

In this case, full day name is obtained from 'DD', so your updated code might look like:

$('#datepicker').datepicker({
    onSelect: function (dateText, inst) {
        var d = new Date(dateText);
        $('#weekNumber').val($.datepicker.iso8601Week(d));
        $('#dayName').val($.datepicker.formatDate('DD', d));
    }
});

Fiddle here: http://jsfiddle.net/duffmaster33/zL6m2wck/

like image 22
Duffmaster33 Avatar answered Sep 28 '22 18:09

Duffmaster33