|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Date comparison
I'm a java engineer and having to work with some coldfusion. I have a date var coming in on a query string from a jsp page to a cfm page formatted as MMM-dd-yyyy. I need to see if that date has passed or not. Whether that date is in the future. I do not have the current date available. I'll need to generate that as well.
Thx. |
|
#2
|
|||
|
|||
|
I believe I figured it out...
<cfset removalDate = "na"><!-- comes in 'MMM-dd-yyyy' format -->
<cfif ParameterExists(url.rmdt) AND url.rmdt IS NOT ""> <cfset rmdt = "#url.rmdt#"> <cfset today = "#Now()#"> <cfset todayDate = "#DateFormat(today, 'mmm-dd-yyyy')#"> <cfif DateDiff("d","rmdt","todayDate") GT 0> <cfset removalDate = "now"> <cfelse> <cfset removalDate = "later"> </cfif> </cfif> Any of you cf guys want to dbl check this.... plzzzzzz |
|
#3
|
|||
|
|||
|
I didn't run this to be sure it works but this was my sweep of the code in general.
Code:
<!--- parameterExists() was depricated in CF5. The len( trim() ) call returns true if url.rmdt is not an empty string. I added a check to confirm that rmdt is a date. --->
<cfif isDefined( 'url.rmdt ')
and len( trim( url.rmdt ) )
and isDate( url.rmdt )>
<!--- don't think you need to dateFormat() the now() call in order to use dateDiff() on it. Also, if the diff is greater than 0 the boolean check is true, so you don't actually need to say 'GT 0' in the cfif block --->
<cfif dateDiff( 'd', url.rmdt, now() )>
<cfset removalDate = "now">
<cfelse>
<cfset removalDate = "later">
</cfif>
</cfif>
|
|
#4
|
|||
|
|||
|
Thanks
Thanks for the validation.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Date comparison |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|