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

<HTML>

<HEAD>
<TITLE>
DateAdd Example
</TITLE>
</HEAD>

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

<H3>DateAdd 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>


<CFQUERY name="GetMessages" DATASOURCE="cfsnippets">
SELECT 	UserName, Subject, Posted
FROM	Messages

</CFQUERY>

<P>This example uses DateAdd to determine when a message in
the database will expire.  (The value selected is messages older
than <CFOUTPUT>#value#

<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="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>
</CFOUTPUT>).

<TABLE>
<TR>
	<TD>UserName</TD>
	<TD>Subject</TD>
	<TD>Posted</TD>
</TR>
<CFOUTPUT query="GetMessages">
<TR>
	<TD>#UserName#</TD>
	<TD>#Subject#</TD>
	<TD>#Posted# <CFIF DateAdd(type, value, posted) LT Now()>EXPIRED</CFIF></TD>
</TR>
</CFOUTPUT>
</TABLE>

<FORM action="dateadd.cfm" METHOD="post">

<PRE>
How many units? <INPUT TYPE="Text" NAME="value" VALUE="<CFOUTPUT>#value#</CFOUTPUT>">
What kind of unit?
	<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>       
