473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

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

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
Nov 21 '07 #1
14 1184
Hi,

The best solution would be to use a server language to include the JS
file conditionally in the HTML.

If it's not possible, you can use the following JS code to check the
date:

var date = new Date(), m = date.getMonth() + 1;
if (m >= 11 || (m == 1 && date.getDate() <= 10)) {
// ...
}

Julien

On Nov 21, 10:55 am, "Mika" <a...@anon.comwrote:
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
Nov 21 '07 #2
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.

"Julien Royer" <el*******@gmail.comwrote in message
news:ee**********************************@b32g2000 hsa.googlegroups.com...
Hi,

The best solution would be to use a server language to include the JS
file conditionally in the HTML.

If it's not possible, you can use the following JS code to check the
date:

var date = new Date(), m = date.getMonth() + 1;
if (m >= 11 || (m == 1 && date.getDate() <= 10)) {
// ...
}

Julien

On Nov 21, 10:55 am, "Mika" <a...@anon.comwrote:
>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

Nov 21 '07 #3
Mika said the following on 11/21/2007 5:41 AM:
Thanks, what is the result of the calculation you put below?
If you can't figure that out, you might not want to be mucking with js
files.
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.
That is what the code does.
Can anyone provide the exact code to place at the top of our .js file to
enable this?
What people can do and what people will do are two different things.

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

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 21 '07 #4
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');

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Nov 22 '07 #5
Evertjan. said the following on 11/22/2007 4:54 AM:
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 didn't write the one I posted, I copied it from an earlier post in the
thread. But, I actually like your version better because it allows you
to simply change the dates for the range, rather than having to re-write
the if statement completely.

Changing it to a 1/10 - 2/14 message would be a lot simpler in yours
than the first one.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 22 '07 #6
"Evertjan." <ex**************@interxnl.netwrote in message
news:Xn********************@194.109.133.242...
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!)
Nov 22 '07 #7
"Randy Webb" <Hi************@aol.comwrote in message
news:9s*********************@giganews.com...
Mika said the following on 11/21/2007 5:41 AM:
>Thanks, what is the result of the calculation you put below?

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.
>Can anyone provide the exact code to place at the top of our .js file to
enable this?

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.
Nov 22 '07 #8
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.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Nov 22 '07 #9
Mika said the following on 11/22/2007 12:48 PM:
"Randy Webb" <Hi************@aol.comwrote in message
news:9s*********************@giganews.com...
>Mika said the following on 11/21/2007 5:41 AM:
>>Thanks, what is the result of the calculation you put below?
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.
I didn't "need" to reply even if I wanted to assist. I replied for no
other reason than I wanted to. That's the way Usenet works sometimes.
You may want to read my reply to Mika though. It explains *exactly* what
you needed to know.
>>Can anyone provide the exact code to place at the top of our .js file to
enable this?
What people can do and what people will do are two different things.

Fascinating.
Glad I could fascinate you.
>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.
You may want to re-read Evertjan's post, then go remove your foot from
your mouth. Or at least put some seasoning on it :)
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.
It isn't limited to JS programmers, it's a Usenet thing.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 22 '07 #10
"Evertjan." <ex**************@interxnl.netwrote in message
news:Xn********************@194.109.133.242...
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.
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 is easier to read that way.

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...
Nov 22 '07 #11
In comp.lang.javascript message <Xn********************@194.109.133.242>
, Thu, 22 Nov 2007 09:54:39, Evertjan. <ex**************@interxnl.net>
posted:
>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') )

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
Web <URL:http://www.merlyn.demon.co.uk/- w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/- see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Nov 22 '07 #12
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){
...........
==================

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Nov 23 '07 #13
"Mika" <an**@anon.comwrote in message
news:tg*******************@text.news.blueyonder.co .uk...
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.
Nov 23 '07 #14

"Tom" <to*@to.comwrote in message news:fi********@drn.newsguy.com...
On Fri, 23 Nov 2007 18:21:13 GMT, Mika wrote...
>>
"Mika" <an**@anon.comwrote in message
news:tg*******************@text.news.blueyonder. co.uk...
>>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.


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.
Nov 23 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bob Murdoch | last post by:
I'm developing an intranet application using W2k server and IE5.5 - 6.x clients. I've got one particular function that calls a stored procedure to update a number of records, depending on user...
12
by: Stuart MacMartin | last post by:
Looking for tricks for speeding up builds... We have an application with about 970 of our own classes of various sizes plus a fair number of routines. Over the past year the compile/link time...
1
by: RobMea | last post by:
I am trying to find a solution to the following problem. First off I'm new to Access and SQL but have a good back ground in other languages, thus at a new job this has just been dumped on me so...
3
by: Paul Aspinall | last post by:
Hi I want to write a piece of code, that will check if a particular service is running on a particular machine. Can someone give me a pointer as to which classes would be useful?? Any sample code...
16
by: TB | last post by:
Hi all: If you think that the following comments are absolute amateurish, then please bear with me, or simply skip this thread. A couple of months back I made the decision to initiate a...
1
by: Michael Groeger | last post by:
Hi NG, I have written a service which should start at certain time in the morning and stop at a certain time in the evening. For this, I added the following to the Main() method of the service:...
9
by: JJM0926 | last post by:
I'm trying to create a running totals query in access 97. I have followed the directions on how to do it from Microsofts website article id 138911. I took their code they had and replaced it with...
5
by: =?Utf-8?B?cnZhbmdlbGRyb3A=?= | last post by:
Hello, I have a problem with our OnlineBackupService.exe. This is a Windows Service which is built in .Net 1.1 and basically grabs files from the file system and will try to upload them using...
1
by: martin DH | last post by:
Slightly related previous posts: (http://www.thescripts.com/forum/thread720001.html) and (http://www.thescripts.com/forum/thread708234.html). Okay, I've had to go back the drawing board a couple...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.