Re: day of month



Prophet wrote:
I have a page which lists of locations of meetings that occur on specific days of the week (every 1st and 3rd Thursday the meeting is in Langley - as an example)

The following code works for when it is the day of the week, but I have a problem when I list tomorrows meeting and today's date is the last day of the week - it will not recognise the 1st day of the next moth as being tomorrows date.

That is because you get today's date, then if it's less than 10 you convert it to a a string, otherwise you keep it as a number.




I know this is probably very crude, but this is what I have been using - any ideas???




<script language="JavaScript">

The language attribute is deprecated, type is required:

  <script type="text/javascript">


<!--

HTML comment delimiters inside script elements serve no useful purpose and are potentially harmful - just don't use them.



 function tomorrow() {

    var mydate=new Date()
  var day=mydate.getDay()
  var daym=mydate.getDate()
    if (daym<10)
    daym="0"+daym
  var tom=day+1

If tom should be the day number for tomorrow:

    var tom = (day + 1)%7;


var daymtom=daym+1

If daymtom should be tomorrow's date:

    mydate.setDate(mydate.getDate() + 1);
    var daymtom = mydate.getDate();


mydate has now been set to tomorrow, but you don't use it anymore so it should be OK.



You may want to use a function to add the leading zero:

function addZ(n)
{
  return (x<10)? '0'+x : ''+x;
}

Ensures n is always returned as a string (if that's what you want). Now the line:


var daym=mydate.getDate()


becomes:

    var daym = addZ(mydate.getDate());


and the following 'if' statement is redundant.




var week1array=new Array("No Meeting","Surrey","Cloverdale","No Meeting","Langley","No Meeting","No Meeting")

You may find it easier for maintenance to initialise arrays:

   var week1array = [
       "No Meeting",
       "Surrey",
       "Cloverdale",
       "No Meeting",
       "Langley",
       "No Meeting",
       "No Meeting"
   ]


Maybe it's generated code so it doesn't matter...


var week2array=new Array("No Meeting","No Meeting","Whiterock","Abbotsford","Hope","No Meeting","No Meeting")


if ((daymtom)<8)
{document.write("<small><font face='Arial'><b>"+week1array[tom]+"</b></font></small>")}
else if ((daymtom)<15)
{document.write("<small><font face='Arial'><b>"+week2array[tom]+"</b></font></small>")}
else if ((daymtom)<22)
{document.write("<small><font face='Arial'><b>"+week1array[tom]+"</b></font></small>")}
else if ((daymtom)<29)
{document.write("<small><font face='Arial'><b>"+week2array[tom]+"</b></font></small>")}
else
{document.write("No Meeting")}

Are meetings never held on the 29th, 30th or 31st?


}

There are a variety of rules to determine which week of the month you are in, make sure users understand what algorithm you are using. Seems to me your week number is given by:


  var weekNum = Math.floor((daymtom-1)/7) + 1;


What do you do for dates beyond 28?


[...]


-- Rob .



Relevant Pages

  • Re: detect the available browser size
    ... var screen_height = screen.height; ... me in a meeting and asked me to look at a serious problem he ... own programming days that, ... the computer would either hang or execute ...
    (comp.lang.javascript)
  • Re: detect the available browser size
    ... var screen_height = screen.height; ... me in a meeting and asked me to look at a serious problem he ... the computer would either hang or execute ... random instructions. ...
    (comp.lang.javascript)
  • Re: Development Question: How to tell if SPWeb is a Document WorkSpace?
    ... Microsoft.SharePoint.SPWeb) As String ... Dim subSite As SPWeb ... >> document workspaces, and other sub webs. ... >> that where made with a meeting template. ...
    (microsoft.public.sharepoint.windowsservices)
  • Re: A simple metaobject protocol for packages
    ... Christophe Rhodes wrote: ... string for google to find anything myself. ... Meeting: some details are at ...
    (comp.lang.lisp)
  • Re: Vermont SWUG Meeting with John McEleney
    ... meeting June 22nd. ... weldment technical session by SW VAR CAD Edge. ... As someone who attended the Los Angeles user group meeting, ... The good part is his candor in the q&a session that follows it. ...
    (comp.cad.solidworks)