Dates, Tomorrow and Next Day

S

Smoke

I have a successful script for determining today's date.

Does anyone have anything for determining tomorrow and the next day since it
would have to look at the day of month and month of year?

Thanks in advance.
 
L

Lasse Reichstein Nielsen

Smoke said:
I have a successful script for determining today's date.

Like
var today = new Date();
?
Does anyone have anything for determining tomorrow and the next day since it
would have to look at the day of month and month of year?

The FAQ gives this link to information on dates:
<URL:http://www.merlyn.demon.co.uk/js-dates.htm>
If it isn't there, it's not worth knowing.

To get the day after today (or after any day), do:

var day = new Date();
day.setDate(day.getDate()+1);

/L
 
S

Smoke

I cannot see from the info on your link or from your not below how this
would work. I believe also you answered my question the other week, thanks
again for that. Below is what is working. If today was the 31st of December
2003, how would a script look that would know to automatically know that
tomorrow would be 01012004?

var d = new Date();

var filename = "" + (d.getMonth() + 1) + (d.getDate()) + (d.getFullYear());

var fileextension = ".gif";

var file = filename + fileextension;

document.write("<img src=http://www.website.com/graphics/"+file+"
width='358' height='233' border='0' alt='' >");

the url below is only good for today

http://www.xatrium.com/fishing/today.htm
 
E

Evertjan.

Smoke wrote on 19 nov 2003 in comp.lang.javascript:
I cannot see from the info on your link or from your not below how
this would work.

[please do not underquote on usenet]

Try this:

<SCRIPT>
var myday = new Date(2003,12,31);
alert(myday)
myday.setDate(myday.getDate()+1);
alert(myday)
</SCRIPT>

As you see a day set to 2003-12-32
will be automaticly be stored by .setDate as 2004-01-01.
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
news:comp.lang.javascript said:
Smoke wrote on 19 nov 2003 in comp.lang.javascript:
I cannot see from the info on your link or from your not below how
this would work.

[please do not underquote on usenet]
^^^^^^^^^^

That word actually means "quote too little". The chief sin is in fact
overquoting. Try "Please do not bottom-quote in News".

As you see a day set to 2003-12-32
will be automaticly be stored by .setDate as 2004-01-01.

OP : see <URL:http://www.merlyn.demon.co.uk/js-date1.htm#FR>, Field
Rollover.
 
M

Michael Winter

Evertjan. wrote on 19 Nov 2003:
Smoke wrote on 19 nov 2003 in comp.lang.javascript:
I cannot see from the info on your link or from your not below how
this would work.

[please do not underquote on usenet]

Try this:

<SCRIPT>
Type?

var myday = new Date(2003,12,31);

This isn't correct. Those values will produce a date of Saturday, 31
January 2004. Month ordinals, when used with the getMonth/setMonth
methods, their UTC counterparts, and the Date constructor, are zero
based. The correct assignment is:

var myday = new Date( 2003, 11, 31 );
alert(myday)
myday.setDate(myday.getDate()+1);
alert(myday)
</SCRIPT>

As you see a day set to 2003-12-32
will be automaticly be stored by .setDate as 2004-01-01.

Mike
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen
in Michael Winter <[email protected].
invalid> posted at Wed, 19 Nov 2003 22:39:28 :-
This isn't correct. Those values will produce a date of Saturday, 31
January 2004. Month ordinals, when used with the getMonth/setMonth
methods, their UTC counterparts, and the Date constructor, are zero
based. The correct assignment is:

var myday = new Date( 2003, 11, 31 );

Yes and no.

If the date is indeed constant, and the numbers are not to be replaced
at a later stage by variables,
var myday = new Date( "2003/12/31" );
is better. It is the same length, the month number is unmistakable, and
it provides an example of ISO-8601 date fields and order (numeric YDM is
never used). A truly enlightened browser would also accept the proper
form "2003-12-31".
 
E

Evertjan.

Michael Winter wrote on 19 nov 2003 in comp.lang.javascript:
This isn't correct. Those values will produce a date of Saturday, 31
January 2004. Month ordinals, when used with the getMonth/setMonth
methods, their UTC counterparts, and the Date constructor, are zero
based. The correct assignment is:

var myday = new Date( 2003, 11, 31 );

You are right, my mistake.

The example stil shows the right result changing the 31st
by storing the 1st of next month.
 
E

Evertjan.

Dr John Stockton wrote on 19 nov 2003 in comp.lang.javascript:
[please do not underquote on usenet]
^^^^^^^^^^

That word actually means "quote too little". The chief sin is in fact
overquoting. Try "Please do not bottom-quote in News".

Right John, the result of posting alsio in Dutch NG's.

You didn't you miss my mistake?
new Date(2003,12,31); // new Date(2003,11,31);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top