By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,480 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,480 IT Pros & Developers. It's quick & easy.

get date of tomorrow, need help

P: n/a
hey guys, I know that you will tell me that's easier to do in php or
even in asp, but I just dont have the time to learn it

1- I need a javascript that will show the date of tomorrow
2- I need a javascript that will show the date in 2 days

actually I have a script that show me the current date....
there it is:

<script>

var dayarray=new Array("Dimanche","Lundi","Mardi","Mercredi","Jeudi ","Vendredi","Samedi")
var montharray=new Array("Janvier","Février","Mars","Avril","Mai","Ju in","Juillet","Août","Septembre","Octobre","Novemb re","Décembre")

function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym

var cdate="<small><font color='000000'
face='Arial'><b>"+dayarray[day]+" "+daym+" "+montharray[month]+"
"+year+"</b></font></small>"

if (document.all)
document.all.clock.innerHTML=cdate
else if (document.getElementById)
document.getElementById("clock").innerHTML=cdate
else
document.write(cdate)
}
if (!document.all&&!document.getElementById)
getthedate()
function goforit(){
if (document.all||document.getElementById)
setInterval("getthedate()",1)
}
</script>
<span id="clock"></span>

For example, I want it to show:
Monday, May 03, 2004(current date)
Tuesday, May 04, 2004
Wednesday, May 05, 2004

I need it in javascript plz :)

Thx for your help.

-Frank
Jul 23 '05 #1
Share this Question
Share on Google+
19 Replies


P: n/a
Fran?ois Laroche wrote:
hey guys, I know that you will tell me that's easier to do in php or
even in asp, but I just dont have the time to learn it

1- I need a javascript that will show the date of tomorrow
2- I need a javascript that will show the date in 2 days

<snip>

function getnewdate(days){
var now = new Date();
var daylength= 1*24*60*60*1000;
var then = new Date(now*1+daylength*days);
alert('now '+now+'\nthen '+then);
}

code source: http://www.codingforums.com/showthread.php?t=37338

Jul 23 '05 #2

P: n/a
On Mon, 03 May 2004 18:37:29 -0700, mscir
<ms***@access4less.com.net.org.uk> wrote:
Fran?ois Laroche wrote:
hey guys, I know that you will tell me that's easier to do in php or
even in asp, but I just dont have the time to learn it

1- I need a javascript that will show the date of tomorrow
2- I need a javascript that will show the date in 2 days

<snip>

function getnewdate(days){
var now = new Date();
var daylength= 1*24*60*60*1000;
var then = new Date(now*1+daylength*days);
alert('now '+now+'\nthen '+then);
}


Wow that's unnessarily complicated. Try

function dateDaysFromNow( days ) {
var d = new Date();
d.setDate( d.getDate() + days );
return d;
}

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #3

P: n/a
Michael Winter wrote:
mscir wrote:
Fran?ois Laroche wrote:
hey guys, I know that you will tell me that's easier to do in php or
even in asp, but I just dont have the time to learn it

1- I need a javascript that will show the date of tomorrow
2- I need a javascript that will show the date in 2 days


<snip>

function getnewdate(days){
var now = new Date();
var daylength= 1*24*60*60*1000;
var then = new Date(now*1+daylength*days);
alert('now '+now+'\nthen '+then);
}


Wow that's unnessarily complicated. Try

function dateDaysFromNow( days ) {
var d = new Date();
d.setDate( d.getDate() + days );
return d;
}


If I add 5 days to today (May 04) I get Jun 14:

function dateDaysFromNow(days) {
var d = new Date();
d.setDate(d.getDate() + days);
alert(d);
}

Mike

Jul 23 '05 #4

P: n/a
On Tue, 04 May 2004 03:48:38 -0700, mscir
<ms***@access4less.com.net.org.uk> wrote:

[snip]
If I add 5 days to today (May 04) I get Jun 14:

function dateDaysFromNow(days) {
var d = new Date();
d.setDate(d.getDate() + days);
alert(d);
}


I get 9th May in IE 6 SP1, Opera 7.23 and Mozilla 1.8a.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #5

P: n/a
mscir <ms***@access4less.com.net.org.uk> writes:
function getnewdate(days){
var now = new Date();
var daylength= 1*24*60*60*1000;
var then = new Date(now*1+daylength*days);
alert('now '+now+'\nthen '+then);
}


As others have pointed out, there are easier ways. This method is also
errorprone when switching to or from daylight saving time.

Where I live (Central European time zone, with daylight saving), I
get see the following problems:
---
var now = new Date(2004,02,27);
now.setHours(23,30,0,0);
alert(now); // 27th of march
var then = new Date(now.valueOf() + 864E5); // daylength == 864E5
alert(then); // 29th of March
---
and
---
var now = new Date(2004,09,31);
now.setHours(0,30,0,0);
alert(now); // 31th of October
var then = new Date(now.valueOf() + 864E5);
alert(then); // still 31th of October
---

Using 864E5 or 24*60*60*1000 is a danger sign, since not all days are that
long.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #6

P: n/a
No time to find the best way to do what I wish so take a look to this:

First, the script I provided will display current date and day

As I said, I need to know the date of tomorrow, and the date in 2 days

<here's my big script that display the date>

the following will only display the day (monday, eetc..)

so....
today:
<script>
var day=new Date();
var when=day.getDay();
switch (when){
case 0:when="Sunday";break;
case 1:when="Monday";break;
case 2:when="Tuesday";break;
case 3:when="Wednesday";break;
case 4:when="Thursday";break;
case 5:when="Friday";break;
case 6:when="Saturday";break;
}
document.write(when)
</script>
tomorrow:
<script>
var day=new Date();
var when=day.getDay()+1;
if (when==7)
var when=0
switch (when){
case 0:when="Sunday";break;
case 1:when="Monday";break;
case 2:when="Tuesday";break;
case 3:when="Wednesday";break;
case 4:when="Thursday";break;
case 5:when="Friday";break;
case 6:when="Saturday";break;
}
document.write(when)
</script>

in 2 days:
<script>
var day=new Date();
var when=day.getDay()+2;
if (when==7)
var when=0
if (when==8)
var when=1
switch (when){
case 0:when="Sunday";break;
case 1:when="Monday";break;
case 2:when="Tuesday";break;
case 3:when="Wednesday";break;
case 4:when="Thursday";break;
case 5:when="Friday";break;
case 6:when="Saturday";break;
}
document.write(when)
</script>

its the easier way to get what I want

example, if this is the current date: Tuesday, May 4 2004

I will see on my website:

Tuesday, May 4 2004

Tuesday (my link here)
Wednesday (other link here)
Thursday (etc.....)
Friday

etc.... etc...

so this is way I resolved my problem, not what I expected before, but
its all good like that.

cya
-Frank
Jul 23 '05 #7

P: n/a
On 4 May 2004 16:54:54 -0700, Fran?ois Laroche <f_*******@videotron.ca>
wrote:
No time to find the best way to do what I wish so take a look to this:

First, the script I provided will display current date and day

As I said, I need to know the date of tomorrow, and the date in 2 days

<here's my big script that display the date>


[snipped script]

An easier way would be to use:

var calendar = new ( function() {
var days = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday' ];

this.getDay = function( delta ) {
var now = new Date();
delta = ( 'number' != typeof delta ) ? 0 : delta;

return days[( now.getDay() + delta ) % 7 ];
};
});

This could easily be expanded to return a fuller date. It also has the
advantage of being able to index far into the future (thousands of days,
if you so wished) without error.

calendar.getDay() // returns "Wednesday" (4th May)
calendar.getDay(1) // returns "Thursday" (5th May)
calendar.getDay(2000) // returns "Monday" (26th Oct, 2009)

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #8

P: n/a
JRS: In article <3d**************************@posting.google.com >, seen
in news:comp.lang.javascript, Fran?ois Laroche <f_*******@videotron.ca>
posted at Tue, 4 May 2004 16:54:54 :
No time to find the best way to do what I wish so take a look to this:

var A = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
X = new Date().getDay()
for (j=0; j<5; j++) document.write(A[(X+j)%7], "<br>")

should be enough to write the current and next few values of day-of-
week.

var A = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
X = new Date()
for (j=0; j<5; j++, X.setDate(X.getDate()+1))
document.write(X.toString().replace(/\d\d:\d\d:\d\d|UTC\S+/g, ""),
"<br>")

will do the same for date, if your toString resembles mine, otherwise,
build YYYY-MM-DD or as needed.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #9

P: n/a
thank you guys

thats nice stuff, I will use it

cya

-Frank
Jul 23 '05 #10

P: n/a
JRS: In article <3d**************************@posting.google.com >, seen
in news:comp.lang.javascript, Fran?ois Laroche <f_*******@videotron.ca>
posted at Wed, 5 May 2004 20:10:32 :
thank you guys

thats nice stuff, I will use it

cya


Please read the FAQ on the proper formatting of News replies
*thoughtfully*, until you understand it. However, you can safely ignore
anything Thomas Lahn may say on the subject.

Don't use slovenly Merkin abbreviations, particularly ambiguous ones;
this is an international newsgroup, and you as a presumed French
Canadian should be able to write proper English.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #11

P: n/a
For anyone else who's going to spend 5 minutes figuring out
what Merkin abbreviations are: American abbreviations.

Csaba Gabor

"Dr John Stockton" <sp**@merlyn.demon.co.uk> wrote in message
news:a8**************@merlyn.demon.co.uk...
JRS: In article <3d**************************@posting.google.com >, seen
in news:comp.lang.javascript, Fran?ois Laroche <f_*******@videotron.ca>
posted at Wed, 5 May 2004 20:10:32 :
thank you guys

thats nice stuff, I will use it

cya
Please read the FAQ on the proper formatting of News replies
*thoughtfully*, until you understand it. However, you can safely ignore
anything Thomas Lahn may say on the subject.

Don't use slovenly Merkin abbreviations, particularly ambiguous ones;
this is an international newsgroup, and you as a presumed French
Canadian should be able to write proper English.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE

4 © <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources. <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items,

links.
Jul 23 '05 #12

P: n/a
> "Dr John Stockton" <sp**@merlyn.demon.co.uk> wrote [...]
Please read the FAQ on the proper formatting of News replies
*thoughtfully*, until you understand it. However, you can safely ignore
anything Thomas Lahn may say on the subject.


Well, I can only find the arrogance sweet that you display here again.
I'll bet who gets a hint about the attribution line is clever enough to
make his/her own conclusions about what is necessary and what is not,
whose recommendations are reasonable and whose are not. Fortunately, I
had not to bear your arrogance and waste time for it for a while since I
had you eventually killfiled. And that was apparently a good decision,
taking into account the unnecessary flames you posted (against me) anyway
(read through quotes in postings of others), only because I/other people
do/did not agree with your humble opinion. Get a life.
PointedEars
Jul 23 '05 #13

P: n/a
JRS: In article <40**************@PointedEars.de>, seen in
news:comp.lang.javascript, Thomas 'PointedEars' Lahn
<Po*********@nurfuerspam.de> posted at Tue, 25 May 2004 08:49:48 :
"Dr John Stockton" <sp**@merlyn.demon.co.uk> wrote [...]
Please read the FAQ on the proper formatting of News replies
*thoughtfully*, until you understand it. However, you can safely ignore
anything Thomas Lahn may say on the subject.


Well, I can only find the arrogance sweet that you display here again.
I'll bet who gets a hint about the attribution line is clever enough to
make his/her own conclusions about what is necessary and what is not,
whose recommendations are reasonable and whose are not. Fortunately, I
had not to bear your arrogance and waste time for it for a while since I
had you eventually killfiled. And that was apparently a good decision,
taking into account the unnecessary flames you posted (against me) anyway
(read through quotes in postings of others), only because I/other people
do/did not agree with your humble opinion. Get a life.


I am pleased to see that, as expected, you do see much of what I write;
and I observe with amusement that you are losing your temper about it.

The treatment will continue for as long as you keep pressing for
compliance with a non-authoritative document that is in conflict with
the RFCs, and has no support in the FAQ. It is necessary to do so in
order to prevent others from being deceived by what you post.

Minimum attribution information may suit you, in your circumstances; but
it is unreasonable and improper to take that as indicating that more
information cannot be beneficial to others.

Normally, the pig-headed attitude that you show is associated with the
earlier stages of adolescence, and should not last, in those of
reasonable intelligence, beyond the age of about sixteen years.

Remember, since you are so young still and might at some stage be in
need of a job, that your posts in Usenet are archived, and posts by
Thomas Lahn may be searched for by potential employers. Good employers
are unlikely to consider mere technical ability as adequate
qualification; they will also look for maturity, judgement, and
willingness to comply with the accustomed usages. But perhaps you could
become a painter instead.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 23 '05 #14

P: n/a
Dr John Stockton wrote:
The treatment will continue for as long as you keep pressing for
compliance with a non-authoritative document that is in conflict with
the RFCs, and has no support in the FAQ.


Is the FAQ an authoritative document?
Who/what gives the authority?

--
Matt Kruse
Javascript Toolbox: http://www.mattkruse.com/javascript/
Jul 23 '05 #15

P: n/a
Dr John Stockton <sp**@merlyn.demon.co.uk> writes:
The treatment will continue for as long as you keep pressing for
compliance with a non-authoritative document that is in conflict with
the RFCs, and has no support in the FAQ. It is necessary to do so in
order to prevent others from being deceived by what you post.


But disagreeing with the message can be done without insulting the
sender. If the purpose of writing is to point out errors to other
readers, attacking the sender merely undermines that message.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #16

P: n/a
rh
Dr John Stockton wrote:
<snip>

I am pleased to see that, as expected, you do see much of what I write;
and I observe with amusement that you are losing your temper about it.

You may wish to consider that what pleases and amuses one can also be
seen to be a measure of the advancement, if any, beyond adolescence or
earlier stages in the maturity progression.
The treatment will continue for as long as you keep pressing for
compliance with a non-authoritative document that is in conflict with
the RFCs, and has no support in the FAQ. It is necessary to do so in
order to prevent others from being deceived by what you post.

Agreed, it should not be presented as some sort of gospel.
Minimum attribution information may suit you, in your circumstances; but
it is unreasonable and improper to take that as indicating that more
information cannot be beneficial to others.

In general, the less noise in the copied response, the better. If the
reader is really interested in the enhanced attribution, it's far
easier to find than the FAQ (which is "required reading").
Normally, the pig-headed attitude that you show is associated with the
earlier stages of adolescence, and should not last, in those of
reasonable intelligence, beyond the age of about sixteen years.

Remember, since you are so young still and might at some stage be in
need of a job, that your posts in Usenet are archived, and posts by
Thomas Lahn may be searched for by potential employers. Good employers
are unlikely to consider mere technical ability as adequate
qualification; they will also look for maturity, judgement, and
willingness to comply with the accustomed usages. But perhaps you could
become a painter instead.


And given the above, you may not be a painter, but certainly display
the burgeoning talent (borrowing from an old joke) of a cunning
linguist.

It's unfortunate that you allow your valued contributions to be
diminished through such paternal, ad hominem mis-adventures.

../rh
Jul 23 '05 #17

P: n/a
JRS: In article <29**************************@posting.google.com >, seen
in news:comp.lang.javascript, rh <co********@yahoo.ca> posted at Wed, 26
May 2004 20:17:30 :
Dr John Stockton wrote: In general, the less noise in the copied response, the better. If the
reader is really interested in the enhanced attribution, it's far
easier to find than the FAQ (which is "required reading").
That depends on the circumstances of the reader. The actual length of
the fullest reasonable attribution is unimportant in comparison with,
for example, the size of an article's header. For those with off-line
readers, a fuller attribution is in general more beneficial than it is
to those who read news while actually connected to the Internet.

Thomas Lahn himself demonstrates this to us. It appears that from time
to time he goes away, and that, when he comes back, he feels it
incumbent on himself to answer a proportion of ancient posts; and it is
his habit to quote only sparsely. This leaves a reader wondering what
is happening. With a dated attribution, the explanation would be
conveniently obvious.

It's unfortunate that you allow your valued contributions to be
diminished through such paternal, ad hominem mis-adventures.


Please do not use a term like /ad hominem/ unless you actually
understand and respect its proper meaning.

--
© John Stockton, Surrey, UK. ??*@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Check boilerplate spelling -- error is a public sign of incompetence.
Never fully trust an article from a poster who gives no full real name.
Jul 23 '05 #18

P: n/a
Dr John Stockton wrote:
JRS: In article <29**************************@posting.google.com >, seen
in news:comp.lang.javascript, rh <co********@yahoo.ca> posted at Wed, 26
May 2004 20:17:30 :
Dr John Stockton wrote:
In general, the less noise in the copied response, the better. If the
reader is really interested in the enhanced attribution, it's far
easier to find than the FAQ (which is "required reading").

That depends on the circumstances of the reader. The actual length of
the fullest reasonable attribution is unimportant in comparison with,
for example, the size of an article's header. For those with off-line
readers, a fuller attribution is in general more beneficial than it is
to those who read news while actually connected to the Internet.

Thomas Lahn himself demonstrates this to us. It appears that from time
to time he goes away, and that, when he comes back, he feels it
incumbent on himself to answer a proportion of ancient posts; and it is
his habit to quote only sparsely. This leaves a reader wondering what
is happening. With a dated attribution, the explanation would be
conveniently obvious.
It's unfortunate that you allow your valued contributions to be
diminished through such paternal, ad hominem mis-adventures.

Please do not use a term like /ad hominem/ unless you actually
understand and respect its proper meaning.


And don't use *ad hominem* arguments....
Mick

Jul 23 '05 #19

P: n/a
rh
Dr John Stockton wrote:
<snip>
It's unfortunate that you allow your valued contributions to be
diminished through such paternal, ad hominem mis-adventures.

Please do not use a term like /ad hominem/ unless you actually
understand and respect its proper meaning.


[ ad hominem:

Etymology: New Latin, literally, to the person

1 : appealing to feelings or prejudices rather than intellect
2 : marked by an attack on an opponent's character rather than by
an answer to the contentions made
]

OK, that's a polite request. I'll make a you a deal -- you try to show
understanding and respect for others, and I'll try to do the same for
terms.

I note the following departures from you usual signature:

-- Check boilerplate spelling -- error is a public sign of
incompetence.

Don't know to what this pertains, nor do I agree with it, so I'll
ignore it (if for nothing other than in order to maintain bliss).

-- Never fully trust an article from a poster who gives no full
real name.

Good advice, and I appreciate the "fully" qualification.

Regards,

../rh

"Never trust a rake without a handle." - author unknown.
Jul 23 '05 #20

This discussion thread is closed

Replies have been disabled for this discussion.