Skip to main content
Inspiring
June 13, 2006
Question

Problem with Date Comparison

  • June 13, 2006
  • 2 replies
  • 328 views
I have an input on a form set to default to todays date. I want to check to see if the date is less than todays date and if so just set it to todays date. I cannot figure out how to do this. Here is my code.

<body>
<cfset todayDate = now()>

<cfquery name="suidsearch" datasource="bldgaccess">
select * from SU_IDs
where EmpNumber = '#suid#'
</cfquery>


<table border="0" cellpadding="0" cellspacing="0" width="1109" leftmargin="0">



<tr>


<td width="84" height=21 class=pad5 style="BORDER-TOP: #ccc 1px dotted; font-weight:bold"><span class="pad5" style="BORDER-TOP: #ccc 1px dotted; font-weight:bold"><cfoutput>#form.suid#</cfoutput></span></td>

<td width="104" align="left" class=pad5 style="BORDER-TOP: #ccc 1px dotted; font-weight:bold"><span class="pad5" style="BORDER-TOP: #ccc 1px dotted; font-weight:bold"><cfoutput>#form.Name#</cfoutput></span></td>

<td width="161" height=21 align="left" class=pad5 style="BORDER-TOP: #ccc 1px dotted; font-weight:bold"><span class="pad5" style="BORDER-TOP: #ccc 1px dotted; font-weight:bold"><cfoutput>#form.bldgarea#</cfoutput></span></td>



<td width="760" align="left" class=pad5 style="BORDER-TOP: #ccc 1px dotted; font-weight:bold"><cfoutput>#form.schedule#</cfoutput></td>
</tr>

</table>

<table border="0" cellpadding="0" cellspacing="0" width="1109" leftmargin="0">
<tr>
<td width="89" class=pad5>Start Date </td>
<td width="104" class=pad5>Exiration Date </td>
<td width="916" colspan="2" class=pad5> </td>
</tr>

<tr>
<form name="form3" method="post" action="confirmation.cfm" target="_self"><td height=21 class=pad5 style="BORDER-TOP: #ccc 1px dotted">
<cfoutput>
<input type="text" name="startdate" style="width:60" value="#dateFormat( todayDate, "mm/dd/yyyy" )#">



</cfoutput>

If anyone has any ideas I would appreciate it. Thanks!
This topic has been closed for replies.

2 replies

Inspiring
June 15, 2006
<cfset todayDate = now()>
<cfif datediff(dateFormat( todayDate, "mm/dd/yyyy" ), startdate) lt 0>
<cfset startdate= dateFormat( todayDate, "mm/dd/yyyy" )>
</cfif>

This should work as long as the user followed instructions to enter using the suggested 'mask' for the date. I would suggest doing error catching code to confirm the 'mask' format is correct on the data entered.
siriivenAuthor
Inspiring
June 15, 2006
Thanks for the reply! I am getting an error when I run the code.

Parameter validation error for function DATEDIFF.
The function takes 3 parameters.

Any ideas?
Inspiring
June 15, 2006
Yup, I goofed. I gave you the wrong function. DateDiff tells you how many 'x' difference there is between two dates. X indicates years, months, days, hours, minutes, or seconds.

I should have given you datecompare().

Change this line:
<cfif datediff(dateFormat( todayDate, "mm/dd/yyyy" ), startdate) lt 0>
to this line
<cfif datediff(datecompare( todayDate, "mm/dd/yyyy" ), startdate) lt 0>

sorry about the confusion.
Participating Frequently
June 13, 2006
Sorry, I am not seeing anything but today's date being displayed on the form. You already set todayDate to now().

Is there a date in the database you want to compare to?

Rob
siriivenAuthor
Inspiring
June 13, 2006
I have an input box that I want to default to todays date when the page is loaded. But if the person wants to enter a future date they can do that. I want to make sure that they cannot enter a date that has already passed. So if they enter 6/1/06 and todays date is 6/13/06 I want the date to be set to the current date.