Fleegix.org

JavaScript DateAdd and DateDiff

2006-01-10 19:24:00

Finally needed some JavaScript code to handle heavy date-manipulation lifting, with all the week-to-week navigation and date-difference calculation happening in Scooby.

I got my start with Web dev working with MS Active Server Pages in VBScript, and whatever else you may say about the general crappiness of that environment, VB does have some seriously nice date handling fu. I got very used to being able to call on DateDiff and DateAdd, and be reasonably sure my results would not be borked.

Of course in JavaScript, you have to do everything yourself -- so I implemented a fairly accurate rendition of those two functions in JavaScript: Date.diff and Date.add. The code is all in the date.js library we use in Scooby -- along with the Date.strftime function which has all the normal datetime/string formatting goodness you'd expect from strftime. The code is available under the Apache License, Version 2.0, and you can download the latest version from OSAF's SVN server.

There are still a few holes here and there -- notably manipulation by 'quarter' interval. But it sure is nice to stop having VB envy with my JS code.

About

This is the blog for Matthew Eernisse. I currently work at Yammer as a developer, working mostly with JavaScript. All opinions expressed here are my own, not my employer's.

Related

Previous posts

All previous posts ยป

This blog is a GeddyJS application.