School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,419 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,520 people online right now. Registration is fast and FREE... Join Now!




How do I make my coldfusion calendar not go before the current date?

 

How do I make my coldfusion calendar not go before the current date?

Zalfel

4 May, 2009 - 01:49 PM
Post #1

New D.I.C Head
*

Joined: 4 May, 2009
Posts: 1

I'm trying to make a calendar in which the days in the month are links to the days themselves, and I need to make sure the customers can't select a date or year prior to the current one. I got the month navigation arrow to work properly but now I have the same thing happening when I go a year ahead. I've started the solution but I can't figure out what needs to be done next. I've used a tutorial to get the basic layout and bare bones of the calendar.

Here's the code:
CODE

<html>
    <head>
        <style>
            .caltexthighlight {
                font-weight: bold;
                font-size: 8pt;
                color: #115e96;
                font-style: normal;
                font-family: verdana, arial, helvetica, sans-serif;
                text-decoration: none;
                padding-bottom: 5px;
                }
            .caltext {
                font-weight: normal;
                font-size: 8pt;
                color: #666666;
                font-style: normal;
                font-family: verdana, arial, helvetica, sans-serif;
                text-decoration: none;
                paddng-bottom: 5px;
                }
            .calendarheader {
                font-weight: bold;
                font-size: 8pt;
                color: #666666;
                font-style: normal;
                font-family: verdana, arial, helvetica, sans-serif;
                text-decoration: none;
                }
            .calendar {
                font-weight: normal;
                font-size: 8pt;
                color: #666666;
                font-style: normal;
                font-family: verdana, arial, helvetica, sans-serif;
                text-decoration: none;
                }
            A.calendar {
                font-weight: bolder;
                font-size: 8pt;
                color: #9c0000;
                font-style: normal;
                font-family: verdana, arial, helvetica, sans-serif;
                text-decoration: underline;
                }
            .calendartoday {
                
                }
            #calContainer {
                float: left;
                width: 450px;
                height: 500px;
            }
            
        </style>
    </head>
    <body marginwidth = 0 marginheight = 0 topmargin = 0 rightmargin = 0 bottommargin = 0>
    <div id = "calContainer">
        <!--- Calendar Code --->
        
        <!--- Declaration of the variables --->
        <!--- Set the month and year parameters to equal the current values if thet do not exist. --->
        <cfparam name = "month" default = "#DatePart('m', Now())#">
        <cfparam name = "year" default = "#DatePart('yyyy', Now())#">
        <cfparam name = "currentday" default = "#DatePart('d', Now())#">
        <cfparam name = "startmonth" default = "#DatePart('m', Now())#">
        <cfparam name = "startyear" default = "#DatePart('yyyy', Now())#">
        
        
        <!--- Set a requested (or current) month/year date  and determine the number of days in the month. --->
        <cfset ThisMonthYear = CreateDate(year, month, '1')>
        <cfset Days = DaysInMonth(ThisMonthYear)>
        
        <!--- Set the values for the previous and next months for the back/next links.--->
        <cfset LastMonthYear = DateAdd('m', -1, ThisMonthYear)>
        <cfset LastMonth = DatePart('m', LastMonthYear)>
        <cfset LastYear = DatePart('yyyy', LastMonthYear)>
        <cfset NextMonthYear = DateAdd('m', 1, ThisMonthYear)>
        <cfset NextMonth = DatePart('m', NextMonthYear)>
        <cfset NextYear = DatePart('yyyy', NextMonthYear)>
        
        
        <cfset PreviousDay = DateAdd('d', -1, ThisMonthYear)>
        <cfset CurrentYear = DatePart('yyyy')>
        
        
        <table border = "1" bgcolor = "#cccccc">
            <tr>
                <td align = "center">
                    <!--- Display the current month/year as well as the back/next links. --->
                    <cfoutput>
                        <nobr>
                            <cfif (#LastMonth# EQ #startmonth# - 1) AND (#CurrentYear# EQ #startyear#)>
                                <u><<</u>
                            <cfelse>
                                <a href = "calendarTest1.cfm?month=#LastMonth#&year=#LastYear#" class = "calendar"><<</a>
                            </cfif>
                            
                            <font class = "caltexthighlight">#MonthAsString(month)# #year#</font>
                            <a href = "calendarTest1.cfm?month=#NextMonth#&year=#NextYear#" class = "calendar">>></a>
                    </cfoutput><br><br>
                    
                    <table border = "1" cellspacing = 0 cellpadding = 0>
                        <!--- Display the day of the week headers.  I've truncated the values to display only the first three letters of each day. --->
                        <tr class = "calendarheader">
                            <cfloop from = "1" to = "7" index = "LoopDay">
                                <cfoutput>
                                    <td width = "15" align = "center">#Left(DayOfWeekAsString(LoopDay), 10)#</td>
                                </cfoutput>
                            </cfloop>
                        </tr>
                        
                        <!--- Set the ThisDay variable to 0. This value will remain 0 until the day of the week on which the first day of the month falls on is reached. --->
                        <cfset ThisDay = 0>
                        <!--- Loop through until the number of days in the month is reached. --->
                        <cfloop condition = "ThisDay LTE Days">
                            <tr class = "calendar">
                            
                            <!--- Loop though each day of the week. --->
                            <cfloop from = "1" to = "7" index = "LoopDay">
                            <!--- This turns each day into a hyperlink if it is a current or future date --->
                                <cfif #PreviousDay# EQ Now() - 1>
                                    <cfoutput>
                                        <a href = "cal_day.cfm">#Days#</a>
                                    </cfoutput>
                                </cfif>
                                
                            <!---
                                If ThisDay is still 0, check to see if the current day of the week in the loop matches the day of the week for the first day of the month.
                                If the values match, set ThisDay to 1.
                                Otherwise, the value will remain 0 until the correct day of the week is found.
                            --->
                                <cfif ThisDay IS 0>
                                    <cfif DayOfWeek(ThisMonthYear) IS LoopDay>
                                        <cfset ThisDay = 1>
                                    </cfif>
                                </cfif>
                            <!---
                                If the ThisDay value is still 0, or is greater than the number of days in the month, display nothing in the column. Otherwise, dispplay
                                the day of the mnth and increment the value.
                            --->
                                <cfif (ThisDay IS NOT 0) AND (ThisDay LTE Days)>
                                    <cfoutput>
                                    <!--- I choose to highlight the current day of the year using an IF-ELSE. --->
                                        <cfif (#ThisDay# EQ #currentday#) AND (#month# EQ #startmonth#) AND (#year# EQ #startyear#)>
                                            <td align = "center">
                                                <cfset dayview = #dateformat(createdate(#year#, #month#, #thisday#), "mm/dd/yyyy")#>
                                                <font class = "calendartoday">#ThisDay#</font>
                                            </td>
                                        <cfelse>
                                            <td align = "center">
                                                <cfset dayview = #dateformat(createdate(#year#, #month#, #thisday#), "mm/dd/yyyy")#>
                                                <font class = "calendar">#ThisDay#</font>
                                            </td>
                                        </cfif>
                                    </cfoutput>
                                    
                                    <cfset ThisDay = ThisDay + 1>
                                    <cfelse>
                                        <td></td>
                                </cfif>
                                
                                
                            </cfloop>
                            </tr>
                    </cfloop>
                    </table>
                </td>
            </tr>
        </table
        
    </div>
    </body>
</html>


This post has been edited by Zalfel: 4 May, 2009 - 09:35 PM

User is offlineProfile CardPM
+Quote Post


simplico

RE: How Do I Make My Coldfusion Calendar Not Go Before The Current Date?

9 May, 2009 - 06:08 AM
Post #2

New D.I.C Head
*

Joined: 9 May, 2009
Posts: 4

you don't need ## in if statements unless it's surrounded by quotes.

but try this:


CODE


                            <cfif (LastYear lt CurrentYear) OR (LastYear lte CurrentYear AND LastMonth lt startmonth)>
                                <<
                            <cfelse>
                                <a href = "test2.cfm?month=#LastMonth#&year=#LastYear#" class = "calendar"><<</a>
                            </cfif>
                            
                            <font class = "caltexthighlight">#MonthAsString(month)# #year#</font>
                            <cfif (NextYear lt CurrentYear) OR (NextYear lte CurrentYear AND NextMonth lt startmonth)>
                                >>
                            <cfelse>
                                <a href = "test2.cfm?month=#NextMonth#&year=#NextYear#" class = "calendar">>></a>
                            </cfif>



User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 11:47PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month