Thoughts from Dan Miser RSS 2.0
# Friday, October 9, 2009
I have several reports in my ASP.NET MVC application that are date-oriented. I had start date and end date text boxes, and things worked fine. What I really wanted was something that would allow those date boxes to be populated with a variety of canned date ranges (e.g. Year to Date, Last Month, etc.). I found just what I was looking for in a pure JavaScript implementation here.

The one problem I found was that "Last Month" was being calculated incorrectly. Below is the simple fix. Thanks to epalla for the original code.


// last month 
case "lastmo":
    // we need a new month variable for month-1, also formatted correctly
    var lastmonth = ((month - 1) < 10) ? "0" + (month - 1) : (month - 1);
    startbox.value = lastmonth + "/01/" + year;

    // now grab the last day of the month (30, 31? we don't know!)
    var moend = new Date(year, (month - 1), 0);
    endbox.value = lastmonth + "/" + moend.getDate() + "/" + year;

    break;
Friday, October 9, 2009 2:44:07 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
ASP.NET | ASP.NET MVC
Navigation
Archive
<October 2014>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2014
Dan Miser
Sign In
Statistics
Total Posts: 388
This Year: 0
This Month: 0
This Week: 0
Comments: 630
Themes
Pick a theme:
All Content © 2014, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)