开发者

JQuery datepicker - Selecting the last day of the month

开发者 https://www.devze.com 2023-03-05 00:31 出处:网络
In a report generator I wrote the user can select a date range to display results for.But since the data for thi开发者_如何学JAVAs report is generated monthly the day portion of the date range is real

In a report generator I wrote the user can select a date range to display results for. But since the data for thi开发者_如何学JAVAs report is generated monthly the day portion of the date range is really irrelevant. I now have the requirement to change the day of the selected start date to '1' regardless of what the user has selected. I've done this like so:

$('#TextStartDate').datepicker({ maxDate: "+0M", minDate: "-24M", dateFormat: 'm/1/yy' });

The second pard of the requirement is that the day of the selected end date be set to the last day of the month regardless of what day was selected. So if the user selected an end date of 5/16/2011 then the date field would show 5/31/2011. This is where I get stuck.

Any help would be greatly appreciated.


The most consistent technique I have found for this is:

  1. Add one month to the select day

  2. Round to the first day of that month

  3. Subtract 1 day.

    Not necessarily pretty, but it works.

Plan B:

  1. Round to first of the selected month
  2. Add 1 month
  3. Subtract 1 day

note: working on a quick sample code will add later

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号