Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2919
  • Last Modified:

Coldfusion flat date picker calendar

I am developing a site that's a bar database that displays events, band and schedules, etc.

One of the features is an event by date calendar. When a date is clicked, any event or  band event that is happening on that day is to be displayed on the selected date.

Its a flat calendar, like the one displayed on this site: http://www.philly2night.com/ (look on the right side)

Event Dates and Band Schedule dates are entered into Access as text. (in the following format: 10-17-2007)

Just looking for a way to display any date that's been clicked on the flat calendar.

Here is an example of the website: http://www.nutsandboltsdesign.com/barreport/

Is there any easy way to get this done? I've been looking around at JavaScript date pickers, but, I havent found anything helpful.
0
meechp123
Asked:
meechp123
  • 7
  • 6
1 Solution
 
mmc98dl1Commented:
check out Ben Nadels blog post on how to print a calender:

http://www.bennadel.com/index.cfm?dax=blog:663.view 

you should be able to adapt this so the link can go off to a page that has your events on it.
0
 
_agx_Commented:
It should be easy using the link mmc98dl1 suggested.

In the calendar, make the "Day" number a link

    <td><a href="YourEventPage.cfm?selDate=#FullDateOfMonth#">#DayOfMonth#</a></td>

Then run a query to get any events for the the selected date. Though, you should also validate the url parameter is a date in the correct format.

   <!--- default to current date if nothing was selected --->
   <cfparam name="url.selDate" default="#DateFormat(now(), 'mm-dd-yyyy')#">
   <cfquery name="getEvents" datasource="YourDataSource">
      SELECT  EventName, EventDetails
      FROM    YourTable
      <!---- should store as date/time not text --->
      WHERE   EventDate = <cfqueryparam value="#url.selDate#" cfsqltype="cf_sql_varchar">
   </cfquery>

   Show events for #url.selDate#:<br>
  <cfoutput query="getEvents">
      Event Name: #EventName#<br>
      Details:  #EventDetails#<br><br>
  </cfoutput>

> dates are entered into Access as text. (in the following format: 10-17-2007)

BUT .. its better to store date values in a "date/time" field so you can take advantage of CF's or your db's date functions.    When you store values as text, searching for "9/7/2007" won't find any matches if the date is entered as "09/07/2007" (ie one has leading zeroes the other doesn't).  You can get around this by using a db function to convert the strings to a "date" but that's less efficient and more error prone than just storing them as a date/time in the first place.


0
 
meechp123Author Commented:
I found this script that seems like it will do what I am looking to accomplish:

http://www.barreport.com/html2/jscalendar.cfm

The author of the script has it programmed for PHP and when you click on a date, it's passing the DATE plus index.php.

I guess I could do something similar with CF, but, I am kind of at a loss of how I would get this done....anyone able to help me out even a little?

This is the script:
<script type="text/javascript">
  function dateChanged(calendar) {
    // Beware that this function is called even if the end-user only
    // changed the month/year.  In order to determine if a date was
    // clicked you can use the dateClicked property of the calendar:
    if (calendar.dateClicked) {
      // OK, a date was clicked, redirect to /yyyy/mm/dd/index.php
      var y = calendar.date.getFullYear();
      var m = calendar.date.getMonth();     // integer, 0..11
      var d = calendar.date.getDate();      // integer, 1..31
      // redirect...
      window.location = "/" + y + "/" + m + "/" + d + "/index.php";
    }
  };

  Calendar.setup(
    {
      flat         : "calendar-container", // ID of the parent element
      flatCallback : dateChanged           // our callback function
    }
  );
</script>

---------------

I was thinking I could something like this (I am not a JS pro by ANY means)

----------
<script type="text/javascript">
  function dateChanged(calendar) {
    // Beware that this function is called even if the end-user only
    // changed the month/year.  In order to determine if a date was
    // clicked you can use the dateClicked property of the calendar:
    if (calendar.dateClicked) {
      // OK, a date was clicked, redirect to /yyyy/mm/dd/index.php
      var y = calendar.date.getFullYear();
      var m = calendar.date.getMonth();     // integer, 0..11
      var d = calendar.date.getDate();      // integer, 1..31
        var selDate = y + m + d();
      // redirect...
      window.location = "/" + y + "/" + m + "/" + d + "/" + selDate + "/" + "testEvents.cfm";
    }
  };

  Calendar.setup(
    {
      flat         : "calendar-container", // ID of the parent element
      flatCallback : dateChanged           // our callback function
    }
  );
</script>
------------------------

testEvents.cfm
----------------
   <!--- default to current date if nothing was selected --->
   <cfparam name="url.selDate" default="#DateFormat(now(), 'mm-dd-yyyy')#">
   <cfquery name="getEventsCalendar" datasource="DSN">
   <!--- --->
   SELECT  e.eventID, e.eventName, e.eventPhone, e.eventEmail, e.eventWebsite, e.eventFee, e.eventAgeID,
                              e.eventTimeTo, e.eventTimeFrom, e.eventDate, e.eventShortDescription, e.eventLongDescription,
                              e.eventImage, e.eventAtmosphereID,
                              e.eventContactPerson, e.featuredEvent,
                              ea.eventAgeID, ea.eventAge,
                              p.placeID, p.placeName, p.placeType,
                              p.placeStreetAddress, p.placeCity, p.placeState, p.placeZip, p.placePhone, p.placeEmail, p.placeWebsite,
                              p.placeDescription, p.placeLogo, p.placeHours, p.placeTypeID,
                              a.eventAtmosphereID,
                              a.eventAtmosphere
      FROM   BRPlaces AS p, EventAge AS ea, BREvents AS e, Events AS e1, EventAtmosphere AS a
      WHERE e.eventDate = <cfqueryparam value="#url.selDate#" cfsqltype="cf_sql_varchar">
            AND ea.EventAgeID = e.EventAgeID
            AND e.EventID = e1.EventID
            AND e1.eventAtmosphereID = a.eventAtmosphereID
 ORDER BY e.EventID, e.eventDate DESC
   </cfquery>



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
   Show events for <cfoutput>#url.selDate#:</cfoutput><br>
  <cfoutput query="getEventsCalendar">
      Event Name: #EventName#<br>
      Details:  #eventLongDescription#<br><br>
  </cfoutput>

</body>
</html>

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
meechp123Author Commented:
i changed the fields from Text to Date/Time as suggested.
0
 
_agx_Commented:
Assuming you have permission to use that script, I think you'd want to pass the selected date as a parameter like this


window.location = "testEvents.cfm?selDate=" + y + "/" + m + "/" + d;
0
 
_agx_Commented:
Don't forget to validate the date parameter

<!--- use the current date if nothing was selected, or the value is invalid --->
<cfif NOT (IsDefined("url.selDate") OR IsDate(url.selDate))>
      <cfset url.selDate = dateFormat(now(), "yyyy/mm/dd")>
</cfif>

And change the cfsqltype to a date/time type

   <cfqueryparam value="#url.selDate#" cfsqltype="cf_sql_date">   ... or ..

   <cfqueryparam value="#url.selDate#" cfsqltype="cf_sql_timestamp">
0
 
meechp123Author Commented:
it works!

it's strange because the events repeat and the calendar is a month behind.

http://www.barreport.com/html2/jscalendar2.cfm

check it out. click on november 30th and october 30th comes up. now. go to december 30th, and the november 30 events will come up and they repeat......
<!--- use the current date if nothing was selected, or the value is invalid --->
<cfif NOT (IsDefined("url.selDate") OR IsDate(url.selDate))>
      <cfset url.selDate = dateFormat(now(), "mm/dd/yyyy")>
</cfif>
 
 
   <!--- default to current date if nothing was selected --->
<cfparam name="url.selDate" default="#DateFormat(now(), 'mm-dd-yyyy')#">
   <cfquery name="getEventsCalendar" datasource="DSN">
   <!--- --->
   SELECT  e.eventID, e.eventName, e.eventPhone, e.eventEmail, e.eventWebsite, e.eventFee, e.eventAgeID,
					e.eventTimeTo, e.eventTimeFrom, e.eventDate, e.eventShortDescription, e.eventLongDescription, 
					e.eventImage, e.eventAtmosphereID,
					e.eventContactPerson, e.featuredEvent,
					ea.eventAgeID, ea.eventAge,
					p.placeID, p.placeName, p.placeType, 
					p.placeStreetAddress, p.placeCity, p.placeState, p.placeZip, p.placePhone, p.placeEmail, p.placeWebsite, 
					p.placeDescription, p.placeLogo, p.placeHours, p.placeTypeID, 
					a.eventAtmosphereID, 
					a.eventAtmosphere 
	FROM   BRPlaces AS p, EventAge AS ea, BREvents AS e, Events AS e1, EventAtmosphere AS a 
	WHERE e.eventDate = <cfqueryparam value="#url.selDate#" cfsqltype="cf_sql_timestamp">
		AND ea.EventAgeID = e.EventAgeID
		AND e.EventID = e1.EventID
		AND e1.eventAtmosphereID = a.eventAtmosphereID 
 ORDER BY e.EventID
   </cfquery>
 
 
 
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
 
<body>
   Show events for <cfoutput>#url.selDate#:</cfoutput><br>
  <cfoutput query="getEventsCalendar">
      Event Name: #eventName#<br>
      Details:  #eventLongDescription#<br><br>
  </cfoutput>
 
</body>
</html>

Open in new window

0
 
_agx_Commented:
Yes, its one month behind because the month is zero-based.  Just add + 1and it should be fine

window.location = "testEvents.cfm?selDate=" + y + "/" + (m+1) + "/" + d;
0
 
_agx_Commented:
Did you add the date validation? Right now it throws and error if you select 03/30/2007 (one month ahead)

InvalidDateTimeException: 2/30/2007 is an invalid date or time string..
0
 
meechp123Author Commented:
I am using       WHERE e.eventDate = <cfqueryparam value="#url.selDate#" cfsqltype="cf_sql_date">

I added the (m+1), thanks so much for that.

Still dont understand why it's repeating.

<!--- use the current date if nothing was selected, or the value is invalid --->
<cfif NOT (IsDefined("url.selDate") OR IsDate(url.selDate))>
      <cfset url.selDate = dateFormat(now(), "mm/dd/yyyy")>
</cfif>


   <!--- default to current date if nothing was selected --->
<!---<cfparam name="url.selDate" default="#DateFormat(now(), 'mm-dd-yyyy')#">--->
   <cfquery name="getEventsCalendar" datasource="DSN">
   <!--- --->
   SELECT  e.eventID, e.eventName, e.eventPhone, e.eventEmail, e.eventWebsite, e.eventFee, e.eventAgeID,
                              e.eventTimeTo, e.eventTimeFrom, e.eventDate, e.eventShortDescription, e.eventLongDescription,
                              e.eventImage, e.eventAtmosphereID,
                              e.eventContactPerson, e.featuredEvent,
                              ea.eventAgeID, ea.eventAge,
                              p.placeID, p.placeName, p.placeType,
                              p.placeStreetAddress, p.placeCity, p.placeState, p.placeZip, p.placePhone, p.placeEmail, p.placeWebsite,
                              p.placeDescription, p.placeLogo, p.placeHours, p.placeTypeID,
                              a.eventAtmosphereID,
                              a.eventAtmosphere
      FROM   BRPlaces AS p, EventAge AS ea, BREvents AS e, Events AS e1, EventAtmosphere AS a
      WHERE e.eventDate = <cfqueryparam value="#url.selDate#" cfsqltype="cf_sql_date">
            AND ea.EventAgeID = e.EventAgeID
            AND e.EventID = e1.EventID
            AND e1.eventAtmosphereID = a.eventAtmosphereID
 ORDER BY e.EventID
   </cfquery>



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
   <p>Show events for <cfoutput>#url.selDate#:</cfoutput><br>
  <cfoutput query="getEventsCalendar">
      Event Name: #eventName#<br>
      Details:  #eventLongDescription#<br />
  </cfoutput></p>

</body>
</html>
0
 
meechp123Author Commented:
0
 
_agx_Commented:
> Still dont understand why it's repeating.

1. You're missing a JOIN in the query.  BRPlaces isn't joined to any of the other tables.  The result is a cartesian product (ie duplicates).  How does BRPlaces relate to the other tables?

            EventAge AS ea, BREvents AS e, Events AS e1, EventAtmosphere AS a

2. The page is throwing an error.  Change the validation code to this

<cfif NOT IsDefined("url.eventDate") OR NOT IsDate(url.eventDate)>
       <cfset url.eventDate = dateFormat(now(), "mm/dd/yyyy")>
</cfif>

3. Make sure the parameter names match.  If you're using "url.eventDate" in the CF code the javascript needs to use that same variable name.  ie

   window.location = "testEvents.cfm?eventDate=" + y + "/" + (m+1) + "/" + d;
   ..
   http://www.barreport.com/html2/testEvents.cfm?eventDate=11/30/2007
0
 
meechp123Author Commented:
Thank you so very much for all your help!
0
 
meechp123Author Commented:
Final code (for anyone to use)

<!--- use the current date if nothing was selected, or the value is invalid --->
<cfif NOT IsDefined("url.eventDate") OR NOT IsDate(url.eventDate)>
       <cfset url.eventDate = dateFormat(now(), "mm/dd/yyyy")>
</cfif>

   <!--- default to current date if nothing was selected --->
<!---<cfparam name="url.selDate" default="#DateFormat(now(), 'mm-dd-yyyy')#">--->
   <cfquery name="getEventsCalendar" datasource="DSN">
   
SELECT  
   eventID,
   eventName,
   eventTimeTo,
   eventTimeFrom,
   eventDate,
   eventShortDescription,
   eventImage
FROM   BREvents
WHERE eventDate = <cfqueryparam value="#url.eventDate#" cfsqltype="cf_sql_date">
ORDER BY EventID
   </cfquery>



<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>BarReport.com events for <cfoutput>#url.eventDate#:</cfoutput></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
   <p>Show events for <cfoutput>#url.eventDate#:</cfoutput><br>
  <cfoutput query="getEventsCalendar">
      <p>Event Name: #eventName#<br>
      Details:  #eventShortDescription#</p>
  </cfoutput></p>
 

</body>
</html>
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now