Datepicker未选择正确的日期

时间:2015-09-22 19:32:26

标签: javascript jquery

date是来自jquery datepicker的值,如果>我想要返回下个月的最后一个日期在日期选择器中挑选了第27个,但是下面的代码总是选择下个月的最后一天是否为> 27日与否?

if (date > date.getMonth(date.getDate() + 0, 27))
{
    date.setMonth(date.getMonth() + 2, 0);
}
else {
    date.setMonth(date.getMonth() + 1);
}

2 个答案:

答案 0 :(得分:1)

要获取当月的某一天,您应该使用Date.prototype.getDate()

if (date.getDate() > 27)
{
  date.setMonth(date.getMonth() + 1);
}

您的变量date可能是String,如果是,那么首先必须将其转换为Date对象:

date = new Date(date);

答案 1 :(得分:0)

首先,您不需要Select sum(Lineamount) as 'Lineamount',sum(qty) as 'Qty' from (Select top(20) SUM(Lineamount) as 'Lineamount',sum(qty) as 'Qty' from CUSTINVOICETRANS c join SALESTABLE s on c.SalesID= s.salesid where s.SALESTYPE =3 and Datepart(YYYY,c.INVOICEDATE) =2014 group by s.CUSTACCOUNT order by SUM(Lineamount) desc). 块。只需检查使用else选择的日期。无需查看月份。

要选择日期,请使用:.getDate(),然后var date = $(this).datepicker('getDate');。这就是你所需要的一切。

完整代码:

if (date.getDate() > 27)

还有一个工作小提琴:http://jsfiddle.net/ugwtkpp1/1/

相关问题