Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calendar Look Ahead

Status
Not open for further replies.

varnix

Programmer
Joined
Jan 7, 2002
Messages
94
Location
US
WE are in the process of creating a scheduling program for use on our intranet. This scheduling program will be used to reserve conference rooms within our company.

Many of our meetings occur "every tuesday" or the first tuesday of a given month. Is there an easy way to have CF scan through and find which dates are Tuesdays or which date is say the first or third Tuesday in a given month.

Thanks!
 
This should give you a start. This will set up a monthly meeting.

<!--- Create variables. --->
<CFSET ViewDate = CreateDate(StartDate_Year,StartDate_Month,StartDate_Day)>
<CFQUERY NAME=&quot;GetTime&quot;
DATASOURCE=&quot;#Application.Datasource#&quot;
DBTYPE=&quot;ODBC&quot;>
SELECT HourCode
FROM HourTable
WHERE HourID = '#Form.StartDate_Hour#'
</CFQUERY>
<CFSET StartHour = GetTime.HourCode>
<CFSET STime = TimeFormat(StartHour,&quot;HH:mm tt&quot;)>
<CFSET ETime = TimeFormat(EndDate_Hour,&quot;HH:mm tt&quot;)>
<CFSET CurrentRoomID = Form.RoomID>

<!--- Initialize DateList --->
<CFSET DateList = &quot;&quot;>
<!--- Create an array and counter variables to hold any conflicts. --->
<CFSET Session.ErrorArray = ArrayNew(2)>
<CFSET RowCounter = 1>

<!--- Assign variables --->
<CFSET TEMPDATE = VIEWDATE>
<CFSET TEMPWEEKDAY = DAYOFWEEK(TEMPDATE)>
<CFSET TEMPMONTH = MONTH(TEMPDATE)>
<CFSET TEMPYEAR = YEAR(TEMPDATE)>
<CFSET TEMPNUM = DAYSINMONTH(TEMPDATE)>
<CFSET TEMPLIST = &quot;&quot;>

<!--- Create a list of all the dates for the given weekday in the current month. --->
<CFLOOP INDEX=&quot;X&quot; FROM=&quot;1&quot; TO=&quot;#TempNum#&quot; STEP=&quot;1&quot;>
<CFSET TEMP = CREATEDATE(TEMPYEAR,TEMPMONTH,X)>
<CFIF DAYOFWEEK(TEMP) EQ TEMPWEEKDAY>
<CFSET TEMPLIST = LISTAPPEND(TEMPLIST,TEMP)>
</CFIF>
</CFLOOP>
<!--- Which occurance of that day of the week is the current date? --->
<CFSET TEMPOCCUR = LISTFIND(TEMPLIST,TEMPDATE)>

<!--- Create an array to hold the dates. --->
<CFSET TEMPARRAY = ARRAYNEW(1)>

<!--- OK, now we want to loop through the months calculate the appropriate days. --->
<CFLOOP INDEX=&quot;Y&quot; FROM=&quot;1&quot; TO=&quot;#Form.Occurances#&quot; STEP=&quot;1&quot;>
<CFSET TEMPVAR = ARRAYAPPEND(TEMPARRAY,DateFormat(TEMPDATE,&quot;mm/dd/yyyy&quot;))>
<CFSET TEMPDATE = DATEADD(&quot;m&quot;,1,TEMPDATE)>
<CFSET TEMPMONTH = MONTH(TEMPDATE)>
<CFSET TEMPYEAR = YEAR(TEMPDATE)>
<CFSET TEMPNUM = DAYSINMONTH(TEMPDATE)>
<CFSET TEMPLIST = &quot;&quot;>
<!--- Create a list of all the dates for the given weekday in the current month. --->
<CFLOOP INDEX=&quot;X&quot; FROM=&quot;1&quot; TO=&quot;#TempNum#&quot; STEP=&quot;1&quot;>
<CFSET TEMP = CREATEDATE(TEMPYEAR,TEMPMONTH,X)>
<CFIF DAYOFWEEK(TEMP) EQ TEMPWEEKDAY>
<CFSET TEMPLIST = LISTAPPEND(TEMPLIST,TEMP)>
</CFIF>
</CFLOOP>
<CFSET TEMPDATE = LISTGETAT(TEMPLIST,TEMPOCCUR)>
</CFLOOP>

<CFSET HOWMANY = ARRAYLEN(TEMPARRAY)>

<CFSET DateList = ArrayToList(TempArray)>

<CFINCLUDE TEMPLATE=&quot;ValidateReccur.cfm&quot;>

<CFLOCATION URL=&quot;DisplayReccuring.cfm?ReccurID=#ReccurID#&RoomID=#CurrentRoomID#&quot; ADDTOKEN=&quot;No&quot;>
Calista :-X
Jedi Knight,
Champion of the Force
 
here you will find javascript code that calculate what day of the week a given date was. It works for leap years and also tells you whether the date is in the past future or today. try to use the basic math procedure to write the cf custom tag that will return the info you need for your application

Sylvano
dsylvano@hotmail.com
 
if you have a look through the commands available in ColdFusion you can use DayOfWeekAsString(DayOfWeek(your_date)) to return the day as a string. Have a look at the help and find all the other functions related to dates. ;-) Erwin Oosterhoorn
Analyst Programmer,
Roller hockey'er, biker, ice hockey fan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top