Advertisement

03.25.2008 at 08:32AM PDT, ID: 23267362 | Points: 300
[x]
Attachment Details
Problem with CreateIODBCDateTime () function
Tags: Coldfusion, Any
I am trying to customize some code and seem to be having a problem with a CF function called CreateODBCDateTime. In my Access database I have a date/time field called EventDate. It is accepting dates/times from a form in the following format;

3/19/2008 6:00:00 AM

I don't want to change this format because another part of the application requires it. Part of my app has a mini calendar grid that when loaded on a page checks that EventDate field,  and if an event exists shows  a link on the mini calendar that then links through to the main calendar for the app. The problem I am having is in this bit of code:
<cftry>
  <cfset newDate = CreateODBCDate(CreateDate(SESSION.cYear, SESSION.cMonth, theDay))>
  <cfset trigger = 1>
<cfcatch>
    <cfset trigger = 0>
</cfcatch>
</cftry>

NewDate is a variable that is used to query the Events table. The above function tries to create a date object. If it is successful, a trigger variable is set to 1. The problem is in my database the EventDate field is set to a date/time field (not just a date) so the CreateODBCDate never successfully creates an object. If I change that function to CreateODBCDateTime, it wants me to add variables for hours, minutes and seconds. How do I create these variables so they will coincide with how my database field is structured? I have tried setting variables for hours, minutes and seconds and then changing the function to CreateODBCDateTime but have not been successful. Below is the remainder of the query code;

<cfif trigger eq 1>
      <cfquery datasource="caldb" name="checkEvent">
      select * from Event
      where EventDate = #newDate#
      </cfquery>
      <!-- If there are some events highlight the backgound of a date cell -->
      <cfif checkEvent.recordcount GT 0>
      <cfset bgrd = "CCCCCC">
      </cfif>
</cfif>

thanks,
   Ken
Start your free trial to view this solution
Question Stats
Zone: Web Development
Question Asked By: kenjpete
Question Asked On: 03.25.2008
Participating Experts: 2
Points: 300
Views: 0
Translate:
Loading Advertisement...
03.25.2008 at 01:56PM PDT, ID: 21206112

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.25.2008 at 07:02PM PDT, ID: 21208291

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.25.2008 at 11:34PM PDT, ID: 21209264

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 01:05PM PDT, ID: 21215625

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 01:11PM PDT, ID: 21215693

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 01:37PM PDT, ID: 21215945

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 01:48PM PDT, ID: 21216044

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.26.2008 at 10:51PM PDT, ID: 21218884

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
03.31.2008 at 08:24AM PDT, ID: 21246217

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
03.25.2008 at 01:56PM PDT, ID: 21206112

Rank: Guru

You were probably not using the createDateTime function when you added the values for hour, minute,  and second.

You can replace the numbers in the code below with your variable names but this is the syntax for creating an odbc datetime string for 03/25/2008 at 1:52:32 pm:
1:
2:
 <cfset newDate = CreateODBCDateTime(CreateDateTime(2008, 03, 25,13,50,32))>
 <cfoutput>#newdate#</cfoutput>
Open in New Window
 
03.25.2008 at 07:02PM PDT, ID: 21208291
Here is what I had previously that didn't seem to work.

First, I set the following variables for hours, minutes and seconds:
<cfset theHour = Hour(Now())>
<cfset theMins = Minute(Now())>
<cfset theSecs = Seconds(Now())>

Then I changed the function to CreateODBCDateTime and added the variables to the method as below:

<cftry>
<cfset newDate = CreateODBCDateTime(CreateDateTime(SESSION.cYear, SESSION.cMonth, theDay, theHour, theMins, theSecs))>
  <cfset trigger = 1>
<cfcatch>
    <cfset trigger = 0>
</cfcatch>
</cftry>

This didn't seem to work? How do I get the hours, minutes and seconds in my database field and those in the object created in the above code to be structured so that the object is successfully created? I don't think I am setting the variables for them correctly?
 
03.25.2008 at 11:34PM PDT, ID: 21209264
I believe the only problem with your code is the Seconds() function.

It should be Second()

No s on the end.

When you are testing code you should comment out the cftry blocks. they hide the message.
At the very least make use of cferror.

Hope that helps.
 
03.26.2008 at 01:05PM PDT, ID: 21215625
I added the following cfset statements to the top of the page:

<cfset theHour = Hour(Now())>
<cfset theMins = Minute(Now())>
<cfset theSecs = Second(Now())>

Changing the Seconds() function to Second() eliminated the errors, but now the mini-calendar is showing links for ALL dates on the calendar, not just ones listed in the EventDate field. I'm wondering if the Now() function is not the correct way to set these variables?

Next,  I commented out the cftry/cfcatch code and re-ran the page, and I got the following error:
**********************************
Date value passed to date function CreateDateTime is unspecified or invalid.  
Specify a valid date in CreateDateTime function.  
 
The error occurred in index1.cfm: line 193
 
191 : trigger is set to 1 -->
192 : <!---<cftry>--->
193 :       <cfset newDate = CreateODBCDateTime(CreateDateTime(SESSION.cYear, SESSION.cMonth, theDay, theHour, theMins, theSecs))>
194 :       <!---<cfset newDate = CreateODBCDate(CreateDate(SESSION.cYear, SESSION.cMonth, theDay))>--->
195 :       <cfset trigger = 1>
**********************************
Any thoughts?

Ken
 
03.26.2008 at 01:11PM PDT, ID: 21215693

Rank: Guru

That error indicates the values SESSION.cYear, SESSION.cMonth, theDay, theHour, theMins, theSecs do not translate to a valid date.  I would output the values of those variables onto the screen so you can make sure they are all numeric values, and that they are valid.
 
03.26.2008 at 01:37PM PDT, ID: 21215945
I did a dump of those variables:

Year = <cfdump var="#Session.cYear#"><br />
Month = <cfdump var="#Session.cMonth#"><br />
Day = <cfdump var="#theDay#"><br />
Hour = <cfdump var="#theHour#"><br />
Minutes = <cfdump var="#theMins#"><br />
Seconds = <cfdump var="#theSecs#"><br />

The output to the screen was the following:

Year = 2008
Month = 3
Day = -5
Hour = 16
Minutes = 30
Seconds = 9

So obviously the day should not be set to -5....the cfset statement for theDay is

<cfloop index ="j" from="1" to="7">
<cfset theDay = pos - (SESSION.startDay-1)>

And, Session.startDay is defineds as
<cfset SESSION.startDay = DayOfWeek(CreateDate(SESSION.cYear,SESSION.cMonth,1))>

Not sure where to go from here, when I leave the function as CreateODBCDate and take the hours, mins, and seconds out of a few of the EventDate fields it all works fine?
 
03.26.2008 at 01:48PM PDT, ID: 21216044

Rank: Guru

in the lines


<cfloop index ="j" from="1" to="7">
<cfset theDay = pos - (SESSION.startDay-1)>


what does pos represent? and what exactly are you trying to calculate with this?
 
03.26.2008 at 10:51PM PDT, ID: 21218884
Also.. how is the session.startDay calculated?

You might want to create a date first CreateDate(NOW()) and then use the DateAdd function to change the date.

Once that has been processed, then use the CreateODBCDateTime function.
 
03.31.2008 at 08:24AM PDT, ID: 21246217
Sorry I haven't posted back, been out sick. As I mentioned I am trying to customize some code for a calendar app, so I'm still figuring parts of this out as well. Here is the code for that entire page.....the pos variable and the Session.startDay variables are initially defined at the top of the page:
****************Start**************************
<!--

Calendar has three atributes a user has to define. The required attribute is a name of a
cfm template in which cf_calendar tag is inserted. For example, if you want to insert
this tag into index.cfm page you have to specify this page as a custom tag
attribute: page = "index.cfm"

-->

<cfparam name="attributes.page" type="string" default="quickcal.cfm">

<!--

There are also two optional attributes that allow to specify ColdFusion
datasource and table name where you keep information about events. If you
do not specify these attributes they are set up as "calendar" datasource
and "calendar" table name by default. If you use your own datasource be sure
that your event table has the following required fields:

id (integer autoincrement)
cdate (date/time general date format in MSAccess)
ctitle (text field)
cdescription (memo field)

-->

<cfparam name="attributes.cdatasource" type="string" default="caldb">
<cfparam name="attributes.ctable" type="string" default="Event">

<!--

To navigate through the calendar a URL parameter URL.mLink is used. If left arrow
clicked, the page in which the calendar is loaded and based on the URL.mLink
parameter the calendar shifts itself either one month ahead (URL.mLink is 2 )
or one month back (URL.mLink is 1 ). By default this parameter is equal zero and
calendar is set up to the current month.

-->    

<cfparam name="URL.mLink" type="numeric" default="0">

<!--Initialization -->

<cfif URL.mLink is 0>
      <cfset SESSION.cMonth = Month(Now())>
      <cfset SESSION.cYear = Year(Now())>
      <cfset SESSION.nDays = DaysInMonth(Now())>
      <cfset SESSION.startDay = DayOfWeek(CreateDate(SESSION.cYear,SESSION.cMonth,1))>
</cfif>

<!-- When the left arrow clicked, the calendar is set up to one month back from the
current month -->

<cfif URL.mLink is 1>
      <cfset SESSION.cMonth = SESSION.cMonth-1>
      <cfif  SESSION.cMonth lt 1>
            <cfset SESSION.cYear = SESSION.cYear-1>
            <cfset SESSION.cMonth = 12>
      </cfif>
      <cfset SESSION.nDays = DaysInMonth(CreateDate(SESSION.cYear, SESSION.cMonth,1))>
      <cfset SESSION.startDay = DayOfWeek(CreateDate(SESSION.cYear, SESSION.cMonth,1))>
</cfif>

<!-- When the right arrow clicked, the calendar is set up to one month forward from the
current month -->
<cfif URL.mLink is 2>
      <cfset SESSION.cMonth = SESSION.cMonth+1>
      <cfif  SESSION.cMonth GT 12>
            <cfset SESSION.cYear = SESSION.cYear+1>
            <cfset SESSION.cMonth = 1>
      </cfif>
      <cfset SESSION.nDays = DaysInMonth(CreateDate(SESSION.cYear, SESSION.cMonth,1))>
      <cfset SESSION.startDay = DayOfWeek(CreateDate(SESSION.cYear, SESSION.cMonth,1))>
</cfif>
<cfset pos = 1>

<!-- Calendar styles is a subject to customization -->

<style type="text/css">
<!--
.style1 {color: #FCFAE9}
.style6 {font-family: Arial; font-size: 12px; }
.style9 {font-family: "Times New Roman", Times, serif; font-size: 12px; color: #FFFFFF; }
-->
</style>

<!-- To output a calendar the tabular format is used. The next code generates 7 x 8 HTML table. First row
is allocated for the calendar navigation (month link). Second row is week days header, and the rest are cells allocated to
display day numbers -->

<cfoutput>
<table width="140"  border="1" cellpadding="0" cellspacing="0" bordercolor="##CCCCCC" bgcolor="##FCFAE9">
<tr valign="middle" bgcolor="0C0F57">
<td height="30" colspan="7" align="center" class="style6">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="30"><a href="#attributes.page#?mLink=1"><img src="http://webserver.ouboces.org/calendar/images/arrow_l.gif" width="20" height="30" border="0"></a></td>
    <td width="100%" align="center" valign="middle" class="style9">#MonthAsString(SESSION.cMonth)# #SESSION.cYear#</td>
    <td width="30"><a href="#attributes.page#?mLink=2"><img src="http://webserver.ouboces.org/calendar/images/arrow_r.gif" width="20" height="30" border="0"></a></td>
  </tr>
</table>
  </td>
</tr>

<tr align="center" valign="middle" bgcolor="0C0F57">
<td width="20" height="20"><span class="style9">Su</span></td>
<td width="20" height="20"><span class="style9">Mo</span></td>
<td width="20" height="20"><span class="style9">Tu</span></td>
<td width="20" height="20"><span class="style9">We</span></td>
<td width="20" height="20"><span class="style9">Th</span></td>
<td width="20" height="20"><span class="style9">Fr</span></td>
<td width="20" height="20"><span class="style9">Sa</span></td>
</tr>
<cfloop index ="i" from="1" to="6">
<tr>
<cfloop index ="j" from="1" to="7">
<cfset theDay = pos - (SESSION.startDay-1)>
<!-- NewDate is a variable that will be used to query Events table. Here the
calendar tries to create a date object. In case of success a triger variable
trigger is set to 1 -->
<cftry>
      <cfset newDate = CreateODBCDate(CreateDate(SESSION.cYear, SESSION.cMonth, theDay))>
      <cfset trigger = 1>
<cfcatch>
      <cfset trigger = 0>
</cfcatch>
</cftry>

<!-- If newDate is a date when an event(s) happen then we link this date in the calendar to
events.cfm page where events for this date will be populated. Otherwise the date in the calendar
will by dysplayed without the link and the highlighted background. This query starts if trigger
variable is set to 1 that means that date is correct -->

<cfset bgrd = "FCFAE9">

<!-- bgrd defines a background color of the cell. The idea is that if the calendar has any events
at this date, the cell background changes its color. You can customize backgrounf color
as it fits the color gamma of your web page -->

<cfif trigger eq 1>
      <cfquery datasource="caldb" name="checkEvent">
      select * from Event
      where EventDate = #newDate#
      </cfquery>
      <!-- If there are some events we highlight the backgound of a date cell -->
      <cfif checkEvent.recordcount GT 0>
      <cfset bgrd = "CCCCCC">
      </cfif>
</cfif>


<td width="20" height="20" align="center" valign="middle" bgcolor="#bgrd#">

<!-- If the date in the right range than it is dysplayed -->
<cfif NOT (theDay LT 1 OR theDay GT SESSION.nDays)>

<cfif trigger eq 1>
<cfif checkEvent.recordcount GT 0>
<a href="quick_add_event_show.cfm?m1=#SESSION.cMonth#&amp;y1=#SESSION.cYear#&amp;d1=#theDay#" target="_blank"><span class="style6">#theDay#</span></a>
<cfelse>
<span class="style6">#theDay#</span>
</cfif>
</cfif>
<!-- Otherwise, the hidden dash is inserted in order to dysplay the table borders correctly -->
<cfelse>
<span class="style1">-</span>
</cfif>

</td>
<cfset pos = pos +1>
</cfloop>
</tr>
</cfloop>
</table>
</cfoutput>
****************End****************************
Again, If I change the EventTime field in my database to be just dates this works fine, but my database is set to time stamp the Event as well, which I need it do for other reasons. I'm trying to change the CreateODBCDate function to CreateODBCDateTime and somehow define variables for hours, mins and seconds that will trigger the newDate variable to create a date/time object when it queries the database.
 
 
20080236-EE-VQP-29 / EE_QW_2_20070628