<!--- This example shows the use of DateDiff --->

<HTML>

<HEAD>
<TITLE>
DateDiff Example
</TITLE>
</HEAD>

<BASEFONT FACE="Arial, Helvetica" SIZE=2>
<BODY  bgcolor="#FFFFD5">

<H3>DateDiff Example</H3>

<CFPARAM name="value" default="3">
<CFPARAM name="type" default="yyyy">

<!--- if numbers passed, then use those --->
<CFIF IsDefined("form.value")>
	<CFSET value = form.value>
</CFIF>
<CFIF IsDefined("form.type")>
	<CFSET type = form.type>
</CFIF>

<CFIF IsDefined("form.date1") and IsDefined("form.date2")>

	<CFIF IsDate(form.date1) and IsDate(form.date2)>
	
		<P>This example uses DateDiff to determine the difference
		in 	<CFSWITCH EXPRESSION=#type#>
			<CFCASE VALUE="yyyy">years</CFCASE>
			<CFCASE VALUE="q">quarters</CFCASE>
			<CFCASE VALUE="m">months</CFCASE>
			<CFCASE VALUE="y">days of year</CFCASE>	
			<CFCASE VALUE="d">days</CFCASE>	
			<CFCASE VALUE="w">weekdays</CFCASE>	
			<CFCASE VALUE="ww">weeks</CFCASE>	
			<CFCASE VALUE="h">hours</CFCASE>	
			<CFCASE VALUE="n">minutes</CFCASE>	
			<CFCASE VALUE="s">seconds</CFCASE>		
			<CFDEFAULTCASE>years</CFDEFAULTCASE></CFSWITCH>
			 dateparts between date1 and date2.
		
		<CFIF DateCompare("#form.date1#","#form.date2#") is not 0>
		<P>The difference is <CFOUTPUT>#Abs(DateDiff(type, form.date2, form.date1))#</CFOUTPUT>
		<CFSWITCH EXPRESSION=#type#>
			<CFCASE VALUE="yyyy">years</CFCASE>
			<CFCASE VALUE="q">quarters</CFCASE>
			<CFCASE VALUE="m">months</CFCASE>
			<CFCASE VALUE="y">days of year</CFCASE>	
			<CFCASE VALUE="d">days</CFCASE>	
			<CFCASE VALUE="w">weekdays</CFCASE>	
			<CFCASE VALUE="ww">weeks</CFCASE>	
			<CFCASE VALUE="h">hours</CFCASE>	
			<CFCASE VALUE="n">minutes</CFCASE>	
			<CFCASE VALUE="s">seconds</CFCASE>		
			<CFDEFAULTCASE>years</CFDEFAULTCASE></CFSWITCH>.
		<CFELSE>
		<P>The two dates are equal!  Try changing one of the values ...
		</CFIF>
	
	<CFELSE>
	<P>Please enter two valid date/time values, formatted like this:
	<CFOUTPUT>#DateFormat(Now())#</CFOUTPUT>	
	</CFIF>	

</CFIF>
<FORM action="datediff.cfm" METHOD="post">

<PRE>
Date 1
<INPUT TYPE="Text" NAME="date1" VALUE="<CFOUTPUT>#DateFormat(Now())#</CFOUTPUT>">
Date 2
<INPUT TYPE="Text" NAME="date2" VALUE="<CFOUTPUT>#DateFormat(Now())#</CFOUTPUT>">
What kind of unit to show difference?
	<SELECT NAME="type">
		<OPTION value="yyyy" SELECTED>years
		<OPTION value="q" >quarter
		<OPTION value="m" >month
		<OPTION value="y" >day of year
		<OPTION value="d" >day
		<OPTION value="w" >weekday
		<OPTION value="ww" >week						
		<OPTION value="h" >hour
		<OPTION value="n" >minute
		<OPTION value="s" >second
		</SELECT>
</PRE>

<INPUT TYPE="Submit" NAME=""><INPUT TYPE="RESET">
</FORM>


</BODY>

</HTML>       
