• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

Check That Date Is Not In The PAst

Hello Can some point me in the right direction as how to check a valid date DD/MM/YYY and time HH:MM that it isnt before DATEFORMAT(NOW()) !!

The following is what i have so far : -

<!-- visitdate (Visit Date) valid date format check -->
<cfif len(FORM.visitdate) and not LSisdate(FORM.visitdate)>
   <cfset VARIABLES.Msg=VARIABLES.Msg & "<li>Visit Date must be in a valid Date Format (DD/MM/YYYY) </li>">
</cfif>
      
<!-- visittime (Visit Time) valid time format check -->
<cfif len(FORM.visittime) and not LSisdate(FORM.visittime)>
   <cfset VARIABLES.Msg=VARIABLES.Msg & "<li>Visit Time must be in a valid Time Format (HH:MM)</li>">
</cfif>
            
<!-- visitdate & visitdate (Visit Date/Time) check not past date/time check  ???????-->
<cfif len(FORM.visitdate) and len(FORM.visittime) and LSisdate("FORM.visitdate FORM.visittime")>
   <cfset VARIABLES.Msg=VARIABLES.Msg & "<li>Visit Date/Time cannot be a past date">
</cfif>
0
jturkington
Asked:
jturkington
  • 3
  • 2
1 Solution
 
mrichmonCommented:
DateCompare(Now(), visitDate)

If it is 0 they are equal.

If it is -1 then Now is less than date (i.e. date is in future)

If it is 1 then now is greater than date (i.e. date is in past)

Documentation
http://livedocs.macromedia.com/coldfusion/6/CFML_Reference/functions-pt156.htm
0
 
mrichmonCommented:
Oh I see there were other parts to the question.  ;o)

<CFIF IsDate(form.visitdate)>
http://livedocs.macromedia.com/coldfusion/6/CFML_Reference/functions-pt1128.htm


to put them together try either
CreateDateTime
http://livedocs.macromedia.com/coldfusion/6/CFML_Reference/functions-pt142.htm#1224498

Or <cfset myvar = DateFormat(visitdate, "DD/MM/YYYY") & " " & TimeFormat(visittime, "hh:mm")>
0
 
jturkingtonAuthor Commented:
What about this mrichmon ?

After the page is posted it checks the the individual date & time, then combines the two and checks for past date, any advice on how to improve this would be much appreciated !!

<!-- visittime (Visit Time) is required -->
<cfif not len(FORM.visittime)>
   <cfset VARIABLES.Msg=VARIABLES.Msg & "<li>You must enter the Visit Time</li>">
</cfif>
      
<!-- visitdate (Visit Date) valid date format check -->
<cfif len(FORM.visitdate) and not LSisdate(FORM.visitdate)>
   <cfset VARIABLES.Msg=VARIABLES.Msg & "<li>Visit Date must be in a valid Date Format (DD/MM/YYYY) </li>">
</cfif>
      
<!-- visittime (Visit Time) valid time format check -->
<cfif len(FORM.visittime) and not LSisdate(FORM.visittime)>
   <cfset VARIABLES.Msg=VARIABLES.Msg & "<li>Visit Time must be in a valid Time Format</li>">
</cfif>
      
<cfif len(FORM.visitdate) and LSisdate(FORM.visitdate) and len(FORM.visittime) and LSisdate(FORM.visittime)>
                  
   <cfset VARIABLES.datetime = FORM.visitdate & " " & FORM.visittime>
                  
   <!-- visitdate & visitdate (Visit Date/Time) check not past date/time check -->
   <cfif len(VARIABLES.datetime) and LSisdate(VARIABLES.datetime) and DateCompare(Now(), VARIABLES.datetime) eq 1>
      <cfset VARIABLES.Msg=VARIABLES.Msg & "<li>Visit Date cannot be a past date">
   </cfif>
</cfif>

Cheers JT
0
 
mrichmonCommented:
Only probelm is that I am not sure if LSisdate will check a valid time format, but otherwise it should be okay.
0
 
jturkingtonAuthor Commented:
Cheers mrichmon, when you get the time can you have a look at :-

http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_21388942.html
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now