Forum Moderators: open

Message Too Old, No Replies

Date question

         

4string

9:52 pm on May 9, 2005 (gmt 0)

10+ Year Member



How would I display the date for the first Saturday of the coming month? Is there a simple function to show that? For instance, it would currently display June 4, 2005 until that day then after that day passes, it'd display the date for the first Saturday in July.

Any help appreciated!

johnl

8:58 am on May 10, 2005 (gmt 0)

10+ Year Member



hi,

you might try:


function firstSatNextMonth()
{
var aktdate, ck, i, nextmo, yr;

aktdate=new Date();
yr=aktdate.getFullYear();
nextmo=aktdate.getMonth()+1;

if(nextmo==12)
{
nextmo=0;
yr+=1;
}

for(i=1; i<8; i++)
{
ck=new Date (yr, nextmo, i);
if(ck.getDay()==6) break;
}
return(ck);
}

This will work for local dates. You perhaps will want to use the functions for UTC-Dates.
For these see the description of the Date object in

[devedge-temp.mozilla.org...]

4string

12:08 pm on May 10, 2005 (gmt 0)

10+ Year Member



Thanks very much! Looks like it'll do the trick.