Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IN BETWEEN QUERY

Status
Not open for further replies.

kingjjx

Programmer
Joined
Sep 18, 2001
Messages
181
Location
US
Hi, I have 2 dropdown boxes in my query page.
the First containing year began .. the 2nd containing year ended.

How do i write the script to query and display results that are in between the year began and year ended.

thank you
 
DateCompare will perform a full date/time comparison of two dates. Returns -1 if date1 is less than date2; returns 0 if date1 is equal to date2; returns 1 if date1 is greater than date2;
save this example as a test.cfm and analize it:

<HTML>
<HEAD>
<TITLE>
DateCompare Example
</TITLE>
</HEAD>
<basefont face=&quot;Arial, Helvetica&quot; size=2>
<H3>DateCompare Example</H3>
<P>The datecompare function compares two date/time values.
<CFIF IsDefined(&quot;FORM.date1&quot;)>
<CFIF IsDate(FORM.date1) and IsDate(FORM.date2)>
<CFSET comparison = DateCompare(FORM.date1, FORM.date2, FORM.precision)>

<!--- switch on the variable to give various responses --->
<CFSWITCH EXPRESSION=#comparison#>
<CFCASE VALUE=&quot;-1&quot;>
<H3><CFOUTPUT>#DateFormat(FORM.date1)#
#TimeFormat(FORM.date1)#</CFOUTPUT> (Date 1) is
earlier than <CFOUTPUT>#DateFormat(FORM.date2)#
#TimeFormat(FORM.date2)#</CFOUTPUT> (Date 2)</H3>
<I>The dates are not equal</I>
</CFCASE>
<CFCASE VALUE=&quot;0&quot;>
<H3><CFOUTPUT>#DateFormat(FORM.date1)#
#TimeFormat(FORM.date1)#</CFOUTPUT> (Date 1) is equal
to <CFOUTPUT>#DateFormat(FORM.date2)#
#TimeFormat(FORM.date2)#</CFOUTPUT> (Date 2)</H3>
<I>The dates are equal!</I>
</CFCASE>
<CFCASE VALUE=&quot;1&quot;>
<H3><CFOUTPUT>#DateFormat(FORM.date1)#
#TimeFormat(FORM.date1)#</CFOUTPUT> (Date 1) is later
than <CFOUTPUT>#DateFormat(FORM.date2)#
#TimeFormat(FORM.date2)#</CFOUTPUT> (Date 2)</H3>
<I>The dates are not equal</I>
</CFCASE>
<CFDEFAULTCASE>
<H3>This is the default case</H3>
</CFDEFAULTCASE>
</CFSWITCH>

<CFELSE>
<H3>Please enter two valid date values</H3>

</CFIF>

</CFIF>

<FORM ACTION=&quot;test.cfm&quot; METHOD=&quot;POST&quot;>
<hr size=&quot;2&quot; color=&quot;#0000A0&quot;>
<P>Date 1
<BR><INPUT TYPE=&quot;Text&quot; NAME=&quot;date1&quot; VALUE=&quot;<CFOUTPUT>#DateFormat(Now())#
#TimeFormat(Now())#
</CFOUTPUT>&quot;>

<P>Date 2
<BR><INPUT TYPE=&quot;Text&quot; NAME=&quot;date2&quot; VALUE=&quot;<CFOUTPUT>#DateFormat(Now())#
#TimeFormat(Now())#
</CFOUTPUT>&quot;>

<P>Specify precision to the:
<BR><select NAME=&quot;precision&quot;>
<option VALUE=&quot;s&quot;>
Second
</OPTION>
<option VALUE=&quot;n&quot;>
Minute
</OPTION>
<option VALUE=&quot;h&quot;>
Hour
</OPTION>
<option VALUE=&quot;d&quot;>
Day
</OPTION>
<option VALUE=&quot;m&quot;>
Month
</OPTION>
<option VALUE=&quot;yyyy&quot;>
Year
</OPTION>
</select>

<P><INPUT TYPE=&quot;Submit&quot; VALUE=&quot;Compare these dates&quot; NAME=&quot;&quot;>
<INPUT TYPE=&quot;RESET&quot;>

</FORM>
</BODY>
</HTML> Sylvano
dsylvano@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top