You are viewing limited content. For full access, please sign in.

Question

Question

Day of Week using dd/MM/yyyy Format

asked on July 14, 2016

I am trying to get a Form to return the day of the week from the input of a Date Picker using the format dd/MM/yyyy

I found the following javascript in Answers:

$(document).ready(function () {
  
  findDay();
  
  function findDay() {
    var d = new Date($('#Field20').val());
    var weekday = new Array(7);
    weekday[0]= "Sunday";
    weekday[1] = "Monday";
    weekday[2] = "Tuesday";
    weekday[3] = "Wednesday";
    weekday[4] = "Thursday";
    weekday[5] = "Friday";
    weekday[6] = "Saturday";
    var n = weekday[d.getDay()];
    $('.dayWeek select').val(n);
    $('.dayWeek select').trigger('change');
  }
  
  $('.reportDate').on('change', 'input', findDay);
  
});

 

The problem is the above script only works if the Date Picker format is M/d/yyyy and the requirement is to have the format as dd/MM/yyyy

Just wondering what alterations are needed to the script to work with the dd/MM/yyyy format.

0 0

Replies

replied on July 14, 2016

It's because the new Date() function can't work well with dd/MM/yyyy format, you can change it to following:

$(document).ready(function () {
   
   findDay();
   
   function findDay() {
     var value= $('.reportDate input').val();
     var parts=value.split("/");
     var d = new Date(parts[2],parts[1]-1,parts[0]);
     var weekday = new Array(7);
     weekday[0]= "Sunday";
     weekday[1] = "Monday";
     weekday[2] = "Tuesday";
     weekday[3] = "Wednesday";
     weekday[4] = "Thursday";
     weekday[5] = "Friday";
     weekday[6] = "Saturday";
     var n = weekday[d.getDay()];
     $('.dayWeek select').val(n);
     $('.dayWeek select').trigger('change');
   }
   
   $('.reportDate').on('change', 'input', findDay);
   
 });

 

1 0
replied on July 14, 2016

Thank you very much - it works perfectly now

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.