getDay() in Javascript Error - Stack Overflow

Can anybody shed some light on getDay() in Javascript please.Here datepicker is textbox where it gets

Can anybody shed some light on getDay() in Javascript please. Here datepicker is textbox where it gets value from Jquery DatePicker Control

var CallbackDateNumber;
// check for the value in Date of callback control
if(("#datepicker")!="")
{
    CallbackDateNumber = new Date($("#datepicker").val()).getDay();
}
else
{
    CallbackDateNumber=new Date().getDay();
}

For January Date its gives 0,1...6- From Sunday to Saturday.

But the same order is not preserved in Month Febraury.

Any reason why this happening?

Can anybody shed some light on getDay() in Javascript please. Here datepicker is textbox where it gets value from Jquery DatePicker Control

var CallbackDateNumber;
// check for the value in Date of callback control
if(("#datepicker")!="")
{
    CallbackDateNumber = new Date($("#datepicker").val()).getDay();
}
else
{
    CallbackDateNumber=new Date().getDay();
}

For January Date its gives 0,1...6- From Sunday to Saturday.

But the same order is not preserved in Month Febraury.

Any reason why this happening?

Share Improve this question edited Jan 31, 2012 at 15:15 Hari Gillala asked Jan 31, 2012 at 15:03 Hari GillalaHari Gillala 11.9k18 gold badges71 silver badges118 bronze badges 3
  • You do realize you are calling two different methods, getDay and getDate, right? – Brian Driscoll Commented Jan 31, 2012 at 15:05
  • for 05/02/2012 I get 3, 06/02/2012 I get 6.for 11/02/2012 I get 5. – Hari Gillala Commented Jan 31, 2012 at 15:17
  • @Brian: that was typo in my original question – Hari Gillala Commented Jan 31, 2012 at 15:18
Add a ment  | 

2 Answers 2

Reset to default 6

You're using getDate() (= day in the month) instead of getDay() (= day of the week) at the else block. Replace getDate with getDay:

CallbackDateNumber = new Date().getDay();

Your dates need to be in MM/DD/YYYY format. It's parsing 05/02/2012 as May 2, 2012 and 06/02/2012 as June 2, 2012.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745443860a4627954.html

相关推荐

  • getDay() in Javascript Error - Stack Overflow

    Can anybody shed some light on getDay() in Javascript please.Here datepicker is textbox where it gets

    9小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信