I have to say that its sort of funny that you surrounded your cf tags
with [php] but i suppose you probably cross posted this to a forum.
Either way, try something like this :
<cfif FORM.year IS NOT "">
AND YEAR(n.due_datetime) = '#FORM.year#'
</cfif>
<cfif FORM.month IS NOT "">
AND MONTH(n.due_datetime) = '#FORM.month#'
</cfif>
<cfif FORM.day IS NOT "">
AND DAY(n.due_datetime) = '#FORM.year#'
</cfif>
This is not tested, and i cant ever remember the differences in the
database types, but you should have some sort of date type functions
that will pull out the specific year month or day from a date and
compare it. It will slow things down, but not any slower than doing a
LIKE. If it doesnt work, you might need to make sure you are storing
it in the db as a timestamp, not a string.
On 12/14/05, Andy Matthews <[EMAIL PROTECTED]> wrote:
> I've got a form which submits 3 fields, year, month and day. In the db, I'm
> storing a standard date/time field (yyyy-mm-dd hh:mm:ss). The time portion
> of this is irrelevant for this form.
>
> What I'd like to accomplish is allowing the user to submit values for one or
> more of these fields and search the date column based on the values. So:
>
> year=2006 (return all records with a year of 2006)
> year=2005, month=12 (return all records from dec 2005)
> month=9, day=21 (return all records on sept 21 of any year.)
> day=21 (return all records on the 21st of any month/year)
>
> Admittedly this last example isn't all that useful, but it's possible. So
> right now this is what my query looks like:
> [php]
> <cfif FORM.year IS NOT "">
> AND n.due_datetime LIKE '#FORM.year#-%'
> </cfif>
> <cfif FORM.month IS NOT "">
> AND n.due_datetime LIKE '%-#FORM.month#-%'
> </cfif>
> <cfif FORM.day IS NOT "">
> AND n.due_datetime LIKE '%-#FORM.year# %'
> </cfif>
> [/php]
>
> The problem is that this only allows the user to search against one of the
> fields; I need to do any/all. Does anyone have any ideas how I might
> accomplish this?
>
> <!----------------//------
> andy matthews
> web developer
> ICGLink, Inc.
> [EMAIL PROTECTED]
> 615.370.1530 x737
> --------------//--------->
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking
application. Start tracking and documenting hours spent on a project or with a
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:227006
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54