decorative image for this page

Handling dates in Javascript

23rd June 2006 15:12 | Categories: Javascript / DHTML, HowTo

A few pointers.

Comparing Dates
If you have two date objects, you need to compare their values returned by their valueOf or getTime methods:

date1.valueOf() > new Date().valueOf()

If you are only after the difference in days, the best way of doing it is:

Math.floor( ( date1 - date2 ) / 86400000 );

Working with weeks
To find the start of the week:

var start = 1; //Mon=1, Tue=2,.., Sun=7 date1.setDate( date1.getDate() - ( date1.getDay() + 7 - start ) % 7 )

this is what fritz looks like

Email | Resume

This is a post within the site. You can navigate through posts via the links labelled 'next', or click on 'search/sitemap' at the top right handside of the page to navigate more quickly.

RSS

ampersand

Fritz is an Italian chap who's been living and working in London for almost 20 years.

He's currently technical director for an integrated digital agency.

In the past he's been a chef, a musician, and author of comics.

home

Serving an Excel Worksheet to a browser.

2006-06-23 15:13 | Tags HowTo, ASP

Writing an excel worksheet to a browser is pretty simple - all you need is the correct response type, and ...

Handling dates in Javascript

2006-06-23 15:12 | Tags Javascript / DHTML, HowTo

A few pointers. Comparing Dates If you have two date objects, you need to compare their values returned by their valueOf or ...

Converting a collection to a JScript object in ASP

2006-05-30 13:04 | Tags HowTo, ASP

Enumerators are collections of data that can be iterated through. Although useful, they are