future date calculation

A

alex.kemsley

Dear All,

I am trying to make a script that prints a date in the format Sunday
14th January 2007. Where the date that is displayed is the next sunday
3 weeks from now. For example today is 7th January. The script would
print Sunday 28th January 2007. It would read that all of this week
until next sunday when it would change to Sunday 4th February.

I am very stuck on where to start so your help would be apreciated.

Regards,

Alex Kemsley
 
E

Evertjan.

alex.kemsley wrote on 07 jan 2007 in comp.lang.javascript:
I am trying to make a script that prints a date in the format Sunday
14th January 2007. Where the date that is displayed is the next sunday
3 weeks from now. For example today is 7th January. The script would
print Sunday 28th January 2007. It would read that all of this week
until next sunday when it would change to Sunday 4th February.

I am very stuck on where to start so your help would be apreciated.

Start with: getDay()
 
L

Lee

alex.kemsley said:
Dear All,

I am trying to make a script that prints a date in the format Sunday
14th January 2007. Where the date that is displayed is the next sunday
3 weeks from now. For example today is 7th January. The script would
print Sunday 28th January 2007. It would read that all of this week
until next sunday when it would change to Sunday 4th February.

I am very stuck on where to start so your help would be apreciated.

var d=new Date();
d.setDate(d.getDate()+21-d.getDay());
alert(d);

Not necessarily formated as you want.


--
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>
alex.kemsley wrote on 07 jan 2007 in comp.lang.javascript:

Start with: getDay()

No. Always start with reading the newsgroup FAQ; see below.

D = new Date()
X = 0
D.setDate(D.getDate()+(6+X-D.getDay())%7 +1 +7*N)

That changes value as the initial D changes from Sat to Sun.

The OP may have an application for which Weeks run Sun..Sat, as in the
Prayer Book. But his E-mail address suggests that he is in a country in
which ISO Weeks, Mon-Sun, are commonly used.

He should consider whether the code may be executed on another country,
and what should then happen.
 
E

Evertjan.

Dr J R Stockton wrote on 07 jan 2007 in comp.lang.javascript:
No. Always start with reading the newsgroup FAQ; see below.

I don't think so John.

If you want to hands-on learn working with a computer language,
hands-on learning being an excellent learning method,

FIRST try yourself,
reading applicable the function definition in the SPECS.

THEN, preferably if that works,
read the FAQ id it can be done simpler, better, faster, etc.

IFALLELSEFAILS, ask in this NG.

ITTERATE the above ad nauseam, or ad successum.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>
Dr J R Stockton wrote on 07 jan 2007 in comp.lang.javascript:


I don't think so John.

If you want to hands-on learn working with a computer language,
hands-on learning being an excellent learning method,
...

Partly true, for those who want to learn a language; but the OP just
asks about a specific problem.

Even those wanting to learn the language should look in the FAQ;
unguided hands-on is rather hit-and-miss, and the FAQ does recommend a
book

BTW, Randy, FAQ 3.1 :
"The Fifth Edition has been released but has not been reviewed well
enough to gain a full endorsement from the regulars of c.l.j." is
ambiguous - does "well" mean "thoroughly" or "favourably"?
 
R

Richard Cornford

Dr J R Stockton wrote:
BTW, Randy, FAQ 3.1 :
"The Fifth Edition has been released but has not been reviewed
well enough to gain a full endorsement from the regulars of c.l.j."
is ambiguous - does "well" mean "thoroughly" or "favourably"?

In my case it means both. Has anyone else said anything informed on the
subject of the 5th edition?

Richard.
 
R

Randy Webb

Richard Cornford said the following on 1/8/2007 7:19 PM:
Dr J R Stockton wrote:


In my case it means both.

To me it would be inclusive of both but at the time it was written it
probably leaned towards thoroughly more than favorably.
Has anyone else said anything informed on the subject of the 5th edition?

To date, I have seen nothing about it.

Good or Bad.
 
R

Randy Webb

Dr J R Stockton said the following on 1/8/2007 5:28 PM:
BTW, Randy, FAQ 3.1 :
"The Fifth Edition has been released but has not been reviewed well
enough to gain a full endorsement from the regulars of c.l.j." is
ambiguous - does "well" mean "thoroughly" or "favourably"?

I have to agree with Richard that it would have to mean both before it
could be endorsed as a "good book" but to date I have seen nothing in
the group about it - good or bad. If there is a wording that is less
ambiguous then I will be happy to change it.
 
E

Evertjan.

Dr J R Stockton wrote on 08 jan 2007 in comp.lang.javascript:
Partly true, for those who want to learn a language; but the OP just
asks about a specific problem.

In general you could be right, but this OP asked:

This could mean, that the OP realy wants to do the programming himself,
but possibliy only was not aware of a weekday function.

=================

.... that incidently has the intransparent name "getDay()",
where I would have suggested "getWeekday()"

... and is also inconsequent in the sense that one would expect there to be
a complementing mirror method "setDay()" [but that woud have a illogical
definition and should be named "setNextWeekday()"]
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>
... that incidently has the intransparent name "getDay()",
where I would have suggested "getWeekday()"

.. and is also inconsequent in the sense that one would expect there to be
a complementing mirror method "setDay()" [but that woud have a illogical
definition and should be named "setNextWeekday()"]

Page <URL:http://www.merlyn.demon.co.uk/js-date8.htm> has code that adds
setDay() to the Date Object. It's analogous to setDate(), setting the
Day without changing the Week or Year (using ISO 8601 week numbering, of
course). It does not actually have setWeek() or the corresponding Year
function; but it does have setYWDarray([Y, W, D]) from which those can
very readily be derived.
 
D

Dr J R Stockton

In comp.lang.javascript message said:
Dr J R Stockton said the following on 1/8/2007 5:28 PM:


I have to agree with Richard that it would have to mean both before it
could be endorsed as a "good book" but to date I have seen nothing in
the group about it - good or bad. If there is a wording that is less
ambiguous then I will be happy to change it.


If it has not been reviewed thoroughly enough, one should not (in such a
brief entry) say whether the review is favourable.

What Richard actually meant is now of no importance; the present need is
for something which is both unambiguous and correct - and which might
encourage an adequate review by someone able enough.

Therefore, if it applies, use just "not ... thoroughly"; else indicate
the favourableness. Just change "well" to "thoroughly" or "favourably".
 
R

Randy Webb

Dr J R Stockton said the following on 1/9/2007 4:50 PM:
If it has not been reviewed thoroughly enough, one should not (in such a
brief entry) say whether the review is favourable.

That is partially why it is worded the way it is.
What Richard actually meant is now of no importance;

It took me a while to figure out what you were referring to with
Richard. I thought you were referring to his reply in this thread (which
is what I agree with) but you seem to be referring to the entry itself.
That is what had me confused as Richard is not the one that put that in
the FAQ, I am.
the present need is for something which is both unambiguous
and correct - and which might encourage an adequate review by
someone able enough.
Agreed.

Therefore, if it applies, use just "not ... thoroughly"; else indicate
the favourableness. Just change "well" to "thoroughly" or "favourably".

The new wording in my local copy says:

The Fifth Edition has been released but has not been reviewed thoroughly
enough to gain a full endorsement from the regulars of c.l.j.

I think to be more in line it should be something like this though:

<proposal>
The Fifth Edition has been released but has not been reviewed thoroughly
enough to gain any type of endorsement from the regulars of c.l.j.
</proposal>

Although that wording seems slanted toward that particular book as the
same thing could be said about many books on Javascript.
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,159
Latest member
SweetCalmCBDGummies
Top