I'm wanting to put a piece of code on my website that will display when our next meeting will be. We have 2 meetings per month. I'm thinking what I need to do is create a code that gets the current month, day of month, and year then combines it together somehow, and if that combination is in a certain range a particular statement, "Next meeting is MM, DD YY." or "Next meeting is today." is displayed.

If date is equal to or between 01012012 and 01112012, "Next meeting is January, 12 2012" is displayed.
If date is equal to 01122012, "Next meeting is today" is displayed.
If date is equal to or between 01132012 and 01252012, "Next meeting is January, 26 2012" is displayed.
If date is equal to 01262012, "Next meeting is today" is displayed.
...that kind of thing.

How would I combine the month, day of month, and year?
Would 48 if statements be what I need to do? :confused:

Sorry, I'm pretty new to javascript. If there's a better way to do this, please let me know.

Thanks,

CJ

xelawho

01-26-2012, 06:51 PM

are the meetings always on the same day of the month (ie, the 12th and the 26th) - if so it could be like this:

CarabinerJ - Do please read the posting guidelines regarding silly thread titles. The thread title is supposed to help people who have a similar problem in future.
Yours is useless for this purpose. You can (and should) edit it to make it more meaningful.

"By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest." - Confucious

CarabinerJ

01-26-2012, 08:34 PM

Sorry! Edited the thread title.

The meetings are always the 2nd and 4th Thursdays of the month. Except November's meetings this year are the 2nd and 5th Thursdays.

For the benefit of future visitors to this thread, I have modified xelawho's excellent script to allow for the situation where in a given month no meetings, or only one meeting, are scheduled. It does not work if there are no meeetings scheduled in two consecutive months!

<html>
<head>
</head>
<body>

<div id="date"></div>

<script type="text/javascript">

// if there is a month with no meeting enter dates as 0,0
// if only one meeting in the month enter as 25,25

oops - forgot about month=11. have added that if. please also note that the meets array is not
var meets = [[12,26], [0,0,0] etc
but var meets = [[12,26],[0],[0],[0] etc
(you only need to put one zero in a month to denote no meeting, and months with one meeting can just have that number - see august)

no - that [0],[0],[0] is to demonstrate what happens if there are no meetings in Feb, Mar or Apr, so "next meeting May 12" is a correct result, being that January's last meeting was the 26th and today is the 28th.

no - that [0],[0],[0] is to demonstrate what happens if there are no meetings in Feb, Mar or Apr, so "next meeting May 12" is a correct result, being that January's last meeting was the 26th and today is the 28th.

Oh, sorry! You are entirely right! I was wrongly expecting a meeting on March 12th. :o

xelawho

01-28-2012, 06:49 PM

no worries, Philip - I appreciate your critical eye.

one question, though: did I just teach my grandmother how to suck an egg? ;)

Philip M

01-28-2012, 06:56 PM

no worries, Philip - I appreciate your critical eye.

one question, though: did I just teach my grandmother how to suck an egg? ;)

Not really. I guess my mind was just working on different lines. This was an interesting problem. Your code is certainly good stuff, but two heads can sometimes be better than one!

There is still a small problem - if the current date is December 28th - 31st the message is "Next meeting is not yet scheduled" rather than the date of the first meeting in January of the following year (here 12th but presumably updated by that time).

resets the "date" to day 0, month+=1 before 32 ever gets tested (because if day==32, it has to be greater than the date of the last meeting of the current month), or at least it seems that way, running the code...

Philip M

01-30-2012, 05:06 PM

Yes, that seems to be it. But I think I will stick with my method! Of course, as we often say, there is more than one way to skin a cat!

I think that really has made the script valuable to the user, and free of gremlins.

satcoucou - Please do not hijack someone else's thread. Prefer to start a new thread of your own. And say exactly what your problem is. You may well find that you can solve it if you take the trouble to Google for "Javascript Date Object".