tags:

views:

1914

answers:

5

I'm looking for a javascript date manipulation library. I googled around some and came up with datejs. The latest version is an alpha-1 release from 2007 so i'm not sure about its quality. Has anyone used this library or do you have another one you can recommend?

I need functions like getWeekNumber(), getFirstDayOfMonth(), getFirstDayOfWeek() etc.

+3  A: 

Have you considered the jquery date library?

http://jqueryjs.googlecode.com/svn/trunk/plugins/methods/date.js

chills42
FYI that file can be included standalone (ie it does not require jQuery nor augments jQuery.fn in any way). It is housed in the plugin repository because it is a dependency of an actual plugin (the datePicker plugin I believe).
JPot
That link is broken and I couldn't find where date.js is currently located. Did it get replaced with something else?
Bill the Lizard
Open source javascript date library (date.js) can be found @ http://www.datejs.com/ or http://code.google.com/p/datejs/
codefoo
+2  A: 

I'm sure 10+ people will say "use jQuery!" very shortly, but it's not hard to roll your own:

Date.prototype.daysInMonth = function ()
{
    var x = 31;
    switch (this.getMonth()) //zero-index
    {
     case 1:  x = (this.isLeapYear? 29 : 28);break;
     case 3:
     case 5:
     case 8:
     case 10: x = 30;
    }
    return x;
};

Date.prototype.isLeapYear = function ()
{
    var y = this.getYear();
    return (y%400==0 || (y%100!=0 && y%4==0));
};

Date.prototype.getMonthName = function ()
{
    return this.toLocaleString().replace(/[^a-z]/gi,'');
};

//etc..
annakata
Yes, you could, but why bother when there's already solutions...
chills42
Indeed, why bother doing anything if someone has already done it :S
annakata
Indeed, why bother at all, right?
KooiInc
A: 

I would recommend using MooTools More's Date class, plus also Date.Extras.

cheeaun
A: 

Most popular javascript frameworks have good modules for date manipulation:

benlenarts
jQuery link down. Any alternative download?
Eduardo Molteni
A: 

Just another option, which I wrote:

DP_DateExtensions Library

Not sure if it'll help, but I've found it useful in several projects.

Supports date/time formatting, date math (add/subtract date parts), date compare, date parsing, etc. It's liberally open sourced.

No reason to consider it if you're already using a framework, but if you just need to quickly add date manipulation to a project give it a chance.

Jim Davis