Running j/s only at certain times of the year?

M

Mika

Hi all

Is there a small addition we can make to a .js file, so that it will only be
read during certain times of the year and ignored at the others? It's for a
Christmas promo.

We want it to run only from 1 Nov - 10 Jan, any year.

Thanks.

Mika
 
M

Mika

Thanks, what is the result of the calculation you put below?

If it is easier we can just go by month, so what we want it to say is:

Is the month Nov or Dec?
No? = Stop script here
Yes? = Continue script...
....then we have our seasonal j/s code here.

Can anyone provide the exact code to place at the top of our .js file to
enable this?

Thanks.
 
S

Steve Swift

Randy said:
If you can't figure that out, you might not want to be mucking with js
files.

I've been programming for over 40 years, and "mucking about" with
JavaScript is about the best I can do. I poke it a bit, and if it
doesn't do what I want I try to find something that will, then I come
and ask the experts.

It's similar to my "skills" in Italian, a language I've never used. The
principle difference is that when I ask simple questions in the Italian
language newsgroups, the Italians are always helpful and friendly.

P.S. My only ever Italian question was for a better translation of
"Forse le lucciole non si amano", the title of one of my favourite CD's,
See, you can even get music recommendations here. :)
 
E

Evertjan.

Randy Webb wrote on 22 nov 2007 in comp.lang.javascript:
var date = new Date(), m = date.getMonth() + 1;
if (m >= 11 || (m == 1 && date.getDate() <= 10)) {

A variation,
[this works EVERY year,
the year 2000 is just for internal use]:

var d = new Date(); d.setYear('2000');
if ( d >= new Date('2000/11/1') ||
d <= new Date('2000/1/10') )
alert('Merry Xmass')
else
alert('Bye');
 
M

Mika

Evertjan. said:
Randy Webb wrote on 22 nov 2007 in comp.lang.javascript:
var date = new Date(), m = date.getMonth() + 1;
if (m >= 11 || (m == 1 && date.getDate() <= 10)) {

A variation,
[this works EVERY year,
the year 2000 is just for internal use]:

var d = new Date(); d.setYear('2000');
if ( d >= new Date('2000/11/1') ||
d <= new Date('2000/1/10') )
alert('Merry Xmass')
else
alert('Bye');

That's brilliant Evertjan, works like a charm. Now it snows at our site
only in the winter! If only there were a way for j/s to determine what
season it is in the user's country ;) (Joke!)
 
M

Mika

Randy Webb said:
Mika said the following on 11/21/2007 5:41 AM:

If you can't figure that out, you might not want to be mucking with js
files.

Got to start somewhere, you didn't need to reply if you didn't want to
assist.
What people can do and what people will do are two different things.
Fascinating.

Please don't top-post. And please don't quote my signature if you reply to
this post.

As not everybody can be right, and as some people believe top-posting is
right, others like bottom-posting, my own rule is to reply in keeping with
the previous post. As Evertjen top-posted, so did I to keep the flow. It
is easier to read that way.

Mika, who doesn't tend to quote people's signatures even without 'being
told', and is trying to work out why many j/s programmers are so angry all
the time.
 
E

Evertjan.

Mika wrote on 22 nov 2007 in comp.lang.javascript:
As Evertjen top-posted, so did I to keep the flow.

"Evertjen", never seen that name,
but I suppose you mean me, Mika.

If I ever did top-post,
it must have been more than 20 years ago.
It is easier to read that way.

It seems you cann't either way.
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]>
Randy Webb wrote on 22 nov 2007 in comp.lang.javascript:
var date = new Date(), m = date.getMonth() + 1;
if (m >= 11 || (m == 1 && date.getDate() <= 10)) {

A variation,
[this works EVERY year,
the year 2000 is just for internal use]:

var d = new Date(); d.setYear('2000');
if ( d >= new Date('2000/11/1') ||
d <= new Date('2000/1/10') )
alert('Merry Xmass')
else
alert('Bye');

I think Mika wanted to include the 10th of January; that will only
include the very beginning of that day.

d < new Date('2000/01/11') )
 
M

Mika

Evertjan. said:
Mika wrote on 22 nov 2007 in comp.lang.javascript:


"Evertjen", never seen that name,
but I suppose you mean me, Mika.

I am so sorry, I typed an 'e' instead of 'a'. I hope you can find a way to
forgive me in time.
If I ever did top-post,
it must have been more than 20 years ago.

Apologies, it was Julien Royer who I was responding to who top-posted.
It seems you cann't either way.

Cann't is spelt either "can't" or "cannot", seeing as this is the pedantic
thread.

Anyway, as I said, thanks for the working code. Sorry your response to my
praise was to pick holes in my reply. Geeez...
 
E

Evertjan.

Evertjan. wrote on 22 nov 2007 in comp.lang.javascript:
Randy Webb wrote on 22 nov 2007 in comp.lang.javascript:
var date = new Date(), m = date.getMonth() + 1;
if (m >= 11 || (m == 1 && date.getDate() <= 10)) {

A variation,
[this works EVERY year,
the year 2000 is just for internal use]:

var d = new Date(); d.setYear('2000');
if ( d >= new Date('2000/11/1') ||
d <= new Date('2000/1/10') )
alert('Merry Xmass')
else
alert('Bye');

I knew you would know better about that, John.

To keep the visual date [and missing the last minute]:

==================
var d = new Date(); d.setYear('2000');
if ( d >= new Date('2000/11/1') ||
d <= new Date('2000/1/10 23:59') )
alert('Merry Xmass')
else
alert('Bye');
==================

or:

==================
function between(dBegin,mBegin,dEnd,mEnd){
var d = new Date(); d.setYear('2000');
return ( d >= new Date('2000/'+mBegin+'/'+dBegin) ||
d <= new Date('2000/'+mEnd+'/'+dEnd+' 23:59') );
}

if ( between(1,11,10,1) ) // dBegin,mBegin,dEnd,mEnd
alert('Merry Xmass')
else
alert('Bye');
==================

or:

==================
function betweenUS(mBegin,dBegin,mEnd,dEnd){
...........
==================
 
M

Mika

Mika said:
Hi all

Is there a small addition we can make to a .js file, so that it will only
be read during certain times of the year and ignored at the others? It's
for a Christmas promo.

We want it to run only from 1 Nov - 10 Jan, any year.

Thanks.

Mika

This was to put snow on our site. For some reason it doesn't work in
Firefox, yet Safari, IE, etc. all work fine.

Can anyone figure out why you don't see snow here on FF only?:
http://tinyurl.com/2s89nv

Thanks.
 
M

Mika

Tom said:
I'm seeing snow fine in FF v2.0.0.9

Maybe you need to use Head & Shoulders shampoo.

....Yep we fixed it thanks, had a rogue 'else' command at the end which broke
it for FF, while IE worked okay.
 

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
474,147
Messages
2,570,835
Members
47,382
Latest member
MichaleStr

Latest Threads

Top