Skip to main content
September 12, 2009
Question

Problem with DateDiff and Date/Time value.

  • September 12, 2009
  • 2 replies
  • 1686 views

The form below displayed perfectly until I added the line for DateDiff between VacStart and VacEnd. I receive an error message;

An error occurred while evaluating the expression:

#DateDiff("w", "VacStart", "VacEnd")#

Error near line 48, column 51.


Parameter 2 of function DateDiff which is now "VacStart" must be a date/time value

The error occurred while processing an element with a general identifier of (#DateDiff("w", "VacStart", "VacEnd")#), occupying document position (48:50) to (48:86).

I have tried changing the DB value to Date/Time as well as Text and get the same result each time. Any help would be greatly appreciated. Here is my code:

<cfquery datasource="manna_premier" name="TM_log">
SELECT *
FROM TMStatusLog
</cfquery>

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>TM Status Log</title>

</head>

<body>

<p align="center" class="style4">Territory Manager Status Log </p>
<table width="1448" border="0">
  <tr>
    <th width="71"><span class="style3">ID No.#</span></th>
<th width="88"><span class="style3"> Date</span></th>
<th width="166"><span class="style3">TM Name</span></th>
<th width="129"><span class="style3">Status</span></th>
<th width="139"><span class="style3">Vac Start </span></th>
<th width="137"><span class="style3">Vac End</span></th>
<th width="203">Ttl Days </th>
<th width="203"><span class="style3">DSR Ride Along Name</span></th>
<th width="274"><span class="style3">Service Call Name</span></th>
  </tr><cfoutput query="TM_log">
  <tr>
    <td><span class="style3">#ID#</span></td>
    <td><div align="center"><span class="style3">#DateFormat(LogDate, "mm/dd/yyyy")#</span></div></td>
    <td><div align="center"><span class="style3">#TerritoryManager#</span></div></td>
    <td><div align="center"><span class="style3">#Status#</span></div></td>
    <td><div align="center"><span class="style3">#DateFormat(VacStart, "mm/dd/yyyy")#</span></div></td>
    <td><div align="center"><span class="style3">#DateFormat(VacEnd, "mm/dd/yyyy")#</span></div></td>
<cfif VacStart IS NOT "Null">
    <td><div align="center"><span class="style3">#DateDiff("w", "VacStart", "VacEnd")#</span></div></td>
</cfif>
    <td><div align="center"><span class="style3">#DSRName#</span></div></td>
    <td><div align="center"><span class="style3">#ServiceName#</span></div></td>
  </tr></cfoutput>
</table>

</body>
</html>

This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
September 13, 2009

Add validation right after the line <cfoutput query="TM_log">, for data that will go into functions. Do something like

<cfoutput query="TM_log">

<!--- Test for valid date data --->
<cfset isLogDateADate = isDate(logDate)>
<cfset isVacStartADate = isDate(vacStart)>
<cfset isVacEndADate = isDate(vacEnd)>

<!--- My example: all dates default to now --->
<cfif NOT isLogDateADate>
    <cfset logdate = now()>
</cfif>
<cfif NOT isVacStartADate>
    <cfset vacStart = now()>
</cfif>
<cfif NOT isVacEndADate>
    <cfset vacEnd = now()>
</cfif>

Inspiring
September 12, 2009

first off lose the quotes around your vars.

#DateDiff("w", VacStart, VacEnd)#

September 12, 2009

I made the changes you suggested and am now getting a new error message:

Error Occurred While Processing Request

Error Diagnostic Information

An error occurred while evaluating the expression:

#DateDiff("w", VacStart, VacEnd)#

Error near line 47, column 48.

Parameter 2 of function DateDiff which is now "" must be a date/time value

The error occurred while processing an element with a general identifier of (#DateDiff("w", VacStart, VacEnd)#), occupying document position (47:47) to (47:79).

Any other suggestions? Thanks!

Inspiring
September 12, 2009

Error Diagnostic Information

An error occurred while evaluating the expression:

#DateDiff("w", VacStart, VacEnd)#

Error near line 47, column 48.

Parameter 2 of function DateDiff which is now "" must be a date/time value

The error occurred while processing an element with a general identifier of (#DateDiff("w", VacStart, VacEnd)#), occupying document position (47:47) to (47:79).

Any other suggestions? Thanks!

Well... what does the error message say?

Parameter 2 of function DateDiff which is now "" must be a date/time value

What does this tell you?  What is parameter 2 of that function call?  It's VacStart.  So it's saying VacStart is an empty string, and it's saying an empty string is not a valid value for that parameter.

So the question you need to ask yourself is whether you expect VacStart to be an empty string?  Or do you perhaps expect it to be a date?  I would guess you're expecting it to be a date.  So the question becomes... Why is VacStart an empty string?

--

Adam