3 Replies Latest reply on Jan 8, 2007 6:14 AM by Newsgroup_User

    Calendar DayofWeek Issue

    Level 7
      Hello - I am having a problem getting a calendar app to show weekend
      days based on a db query. What I have below has the table tags stripped
      so it is easier to read. The code seems to count the first day of the
      month as 1 (a weekend) and then every 7 days as a weekend and so on. I'm
      obviously overlooking something.

      Any help is appreciated.

      <cfset FIRSTOFMONTH=CreateDate(Year(DateOb),Month(DateOb),1)>
      <cfset TOPAD=DayOfWeek(FIRSTOFMONTH) - 1>
      <cfloop index="X" from="1" to="#DaysInMonth(DateOb)#">
      <cfquery name="appshow" datasource="#caldsn#">
      SELECT * FROM eventcal WHERE cal_date = #Createdate(url.ye,url.mo,X)#
      </cfquery>
      <cfoutput>#X#</cfoutput>
      <cfif (dayOfWeek(x) IS 1) OR (dayOfWeek(x) IS 7)>
      Weekend
      <cfelse>
      Weekday
      </cfif>
      </cfloop>

      Thank you,
      Steve Miller
        • 1. Re: Calendar DayofWeek Issue
          Dan Bracuk Level 5
          You are running your day of week function on a number, not a date. That's why you are getting strange answers. You should be running it on cal_date instead of x.

          You are also running very inefficient code. You only need one trip to the db. Try something like this.

          FirstOfMonth = CreateDate(Year(DateOb),Month(DateOb),1);
          NextMonth = DateAdd("m", FirstofMonth, 1);

          Your query then becomes

          select * from eventcal
          where cal_date >= xx
          and cal_date < yy

          xx and yy refer to the two variables you created. To actually use them, you either have to use createodbcdate or cfqueryparam. The former will always work. The latter will usually work.

          • 2. Re: Calendar DayofWeek Issue
            Level 7
            Hi Dan - I will give that a try and let you know how it works. Thank you
            for your help. It's greatly appreciated.

            Steve Miller

            Dan Bracuk wrote:

            >You are running your day of week function on a number, not a date. That's why
            >you are getting strange answers. You should be running it on cal_date instead
            >of x.
            >
            > You are also running very inefficient code. You only need one trip to the db.
            > Try something like this.
            >
            > FirstOfMonth = CreateDate(Year(DateOb),Month(DateOb),1);
            > NextMonth = DateAdd("m", FirstofMonth, 1);
            >
            > Your query then becomes
            >
            > select * from eventcal
            > where cal_date >= xx
            > and cal_date < yy
            >
            > xx and yy refer to the two variables you created. To actually use them, you
            >either have to use createodbcdate or cfqueryparam. The former will always
            >work. The latter will usually work.
            >
            >
            >
            >
            >
            • 3. Re: Calendar DayofWeek Issue
              Level 7
              Dan thank you for your help. It worked perfectly!

              Dan Bracuk wrote:

              >You are running your day of week function on a number, not a date. That's why
              >you are getting strange answers. You should be running it on cal_date instead
              >of x.
              >
              > You are also running very inefficient code. You only need one trip to the db.
              > Try something like this.
              >
              > FirstOfMonth = CreateDate(Year(DateOb),Month(DateOb),1);
              > NextMonth = DateAdd("m", FirstofMonth, 1);
              >
              > Your query then becomes
              >
              > select * from eventcal
              > where cal_date >= xx
              > and cal_date < yy
              >
              > xx and yy refer to the two variables you created. To actually use them, you
              >either have to use createodbcdate or cfqueryparam. The former will always
              >work. The latter will usually work.
              >
              >
              >
              >
              >