get date of tomorrow, need help

  • Thread starter Fran?ois Laroche
  • Start date
F

Fran?ois Laroche

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","Juin","Juillet","Août","Septembre","Octobre","Novembre","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
 
M

Michael Winter

<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
 
M

Michael Winter

On Tue, 04 May 2004 03:48:38 -0700, mscir

[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
 
L

Lasse Reichstein Nielsen

mscir said:
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
 
F

Fran?ois Laroche

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
 
M

Michael Winter

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
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen
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.
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen
in news:comp.lang.javascript said:
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.
 
C

Csaba Gabor

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

Csaba Gabor

Dr John Stockton said:
JRS: In article <[email protected]>, seen


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.
links.
 
T

Thomas 'PointedEars' Lahn

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
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
Thomas 'PointedEars' Lahn
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.
 
M

Matt Kruse

Dr said:
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?
 
L

Lasse Reichstein Nielsen

Dr John Stockton said:
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
 
R

rh

Dr John Stockton wrote:
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
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen
in news:comp.lang.javascript said:
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.
 
M

Mick White

Dr said:
JRS: In article <[email protected]>, seen



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.





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
 
R

rh

Dr John Stockton wrote:
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.
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top