Thread: Date comparison

    #1
  1. No Profile Picture
    Grinder
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    VA
    Posts
    53
    Rep Power
    0

    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. #2
  3. No Profile Picture
    Grinder
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    VA
    Posts
    53
    Rep Power
    0

    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
  4. #3
  5. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,273
    Rep Power
    968
    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>
  6. #4
  7. No Profile Picture
    Grinder
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    VA
    Posts
    53
    Rep Power
    0

    Thanks


    Thanks for the validation.

IMN logo majestic logo threadwatch logo seochat tools logo