House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

SQL between dates problem

  << Previous Post |  RSS |  Tree View |  Sort Oldest First |  Subscribe to this Group Next >> 

SQL between dates problem

"datetime" would be your variable or another column to which you would Dawson, Michael 12/02/2008 09:54 AM
Screw it. I'm just telling my client to enter the day after as the expiration Will Tomlinson 12/02/2008 07:08 AM
>If you are using MS SQL... Will Tomlinson 12/01/2008 08:08 PM
>I would do something like: Will Tomlinson 12/01/2008 01:18 PM
Although this will work perfectly, if provided with CF variables. Dawson, Michael 12/01/2008 10:55 AM
Another CFMLish option: John M Bliss 12/01/2008 10:37 AM
I would do something like: Dawson, Michael 12/01/2008 10:17 AM
>If you are using MS SQL... Will Tomlinson 12/01/2008 10:13 AM
>Try this: Will Tomlinson 12/01/2008 10:12 AM
If you are using MS SQL... Dawson, Michael 12/01/2008 09:50 AM
Try this: Duane Boudreau 12/01/2008 09:47 AM
>Because GETDATE() will return the current date *and time* and I'll bet Will Tomlinson 12/01/2008 09:41 AM
Because GETDATE() will return the current date *and time* and I'll bet John M Bliss 12/01/2008 09:32 AM
SQL server 2000. Will Tomlinson 12/01/2008 09:25 AM

12/02/2008 09:54 AM
Author: Dawson, Michael Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:58204#316107 "datetime" would be your variable or another column to which you would compare the coupon start/end dates. Mike >If you are using MS SQL... > >SELECT CAST(FLOOR(CAST(GETDATE() AS float)) AS datetime) > >This will remove any time part from a datetime field. I'm getting an error from the SQL. I've played around with it with no luck. SELECT couponpercdisc, CAST(FLOOR(CAST(GETDATE() AS float)) AS datetime) FROM tblCoupons WHERE couponcode = <cfqueryparam value="#arguments.couponcode#" cfsqltype="cf_sql_varchar"> AND datetime BETWEEN CAST(FLOOR(CAST(couponstartdate AS float)) AS datetime) AND CAST(FLOOR(CAST(couponenddate AS float)) AS datetime) [Macromedia][SQLServer JDBC Driver][SQLServer]Invalid column name 'datetime' Will
12/02/2008 07:08 AM
Author: Will Tomlinson Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:58204#316103 Screw it. I'm just telling my client to enter the day after as the expiration date of the coupon. It works. But one thing I noticed and tested is, you can insert a date like so into SQL server and it accepts it and converts it to the right format. 12/01/2008 10:37 PM So I could have two inputs for this. A datepicker, and a timepicker, stick them together, and it'd work. Thanks for everyone's input! Will
12/01/2008 08:08 PM
Author: Will Tomlinson Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:58204#316088 >If you are using MS SQL... > >SELECT CAST(FLOOR(CAST(GETDATE() AS float)) AS datetime) > >This will remove any time part from a datetime field. I'm getting an error from the SQL. I've played around with it with no luck. SELECT couponpercdisc, CAST(FLOOR(CAST(GETDATE() AS float)) AS datetime) FROM tblCoupons WHERE couponcode = <cfqueryparam value="#arguments.couponcode#" cfsqltype="cf_sql_varchar"> AND datetime BETWEEN CAST(FLOOR(CAST(couponstartdate AS float)) AS datetime) AND CAST(FLOOR(CAST(couponenddate AS float)) AS datetime) [Macromedia][SQLServer JDBC Driver][SQLServer]Invalid column name 'datetime' Will
12/01/2008 01:18 PM
Author: Will Tomlinson Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:58204#316076 >I would do something like: > >WHERE datetime BETWEEN CAST(FLOOR(CAST(couponstartdate AS float)) AS >datetime) >AND CAST(FLOOR(CAST(couponenddate AS float)) AS datetime) > I'm remote right now, but will give it a whirl tonight. Thanks for your help! Will
12/01/2008 10:55 AM
Author: Dawson, Michael Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:58204#316069 Although this will work perfectly, if provided with CF variables. However, I think Will's dates were already in the database where he would need to stick to the database's date functions. In other words, he wasn't in a situation where he was passing in CF variables to his SQL statement. Mike Another CFMLish option: couponstartdate <= #CreateODBCDateTime(CreateDateTime(DatePart("yyyy", Now()), DatePart("m", Now()), DatePart("d", Now()), 23, 59, 59))# and couponenddate >= #CreateODBCDateTime(CreateDateTime(DatePart("yyyy", Now()), DatePart("m", Now()), DatePart("d", Now()), 0, 0, 1))#
12/01/2008 10:37 AM
Author: John M Bliss Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:58204#316066 Another CFMLish option: couponstartdate <= #CreateODBCDateTime(CreateDateTime(DatePart("yyyy", Now()), DatePart("m", Now()), DatePart("d", Now()), 23, 59, 59))# and couponenddate >= #CreateODBCDateTime(CreateDateTime(DatePart("yyyy", Now()), DatePart("m", Now()), DatePart("d", Now()), 0, 0, 1))# ----- Excess quoted text cut - see Original Post for more -----
12/01/2008 10:17 AM
Author: Dawson, Michael Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:58204#316065 I would do something like: WHERE datetime BETWEEN CAST(FLOOR(CAST(couponstartdate AS float)) AS datetime) AND CAST(FLOOR(CAST(couponenddate AS float)) AS datetime) >If you are using MS SQL... > >SELECT CAST(FLOOR(CAST(GETDATE() AS float)) AS datetime) > >This will remove any time part from a datetime field. > So then I write it like this? AND datetime >= couponstartdate and datetime <= couponenddate Thanks! Will
12/01/2008 10:13 AM
Author: Will Tomlinson Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:58204#316064 >If you are using MS SQL... > >SELECT CAST(FLOOR(CAST(GETDATE() AS float)) AS datetime) > >This will remove any time part from a datetime field. > So then I write it like this? AND datetime >= couponstartdate and datetime <= couponenddate Thanks! Will
12/01/2008 10:12 AM
Author: Will Tomlinson Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:58204#316063 >Try this: > >AND GETDATE() >= '#couponstartdate# 00:00:00' and GETDATE() <= >'#couponenddate# 23:59:59' > Except the values I want to match them against are the value in a column - not a couponstartdate or couponenddate variable. Thanks! Will
12/01/2008 09:50 AM
Author: Dawson, Michael Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:58204#316062 If you are using MS SQL... SELECT CAST(FLOOR(CAST(GETDATE() AS float)) AS datetime) This will remove any time part from a datetime field. Mike >Because GETDATE() will return the current date *and time* and I'll bet >that your start/end dates are coming back as 12/1/2008 12:00 AM. > Ahhh yes! That makes sense. Thanks John! Will
12/01/2008 09:47 AM
Author: Duane Boudreau Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:58204#316061 Try this: AND GETDATE() >= '#couponstartdate# 00:00:00' and GETDATE() <= '#couponenddate# 23:59:59' SQL server 2000. I have two columns - startdate and enddate, why would this not return a record if the startdate and enddate are the same. ex. 12/01/2008 for both. AND GETDATE() >= couponstartdate and GETDATE() <= couponenddate Is there a better way to write this? I need it to return a record. It also seems to not pull the record unless the enddate is one day after the day I want it to expire. Thanks, Will
12/01/2008 09:41 AM
Author: Will Tomlinson Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:58204#316059 >Because GETDATE() will return the current date *and time* and I'll bet >that your start/end dates are coming back as 12/1/2008 12:00 AM. > Ahhh yes! That makes sense. Thanks John! Will
12/01/2008 09:32 AM
Author: John M Bliss Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:58204#316057 Because GETDATE() will return the current date *and time* and I'll bet that your start/end dates are coming back as 12/1/2008 12:00 AM. ----- Excess quoted text cut - see Original Post for more -----
12/01/2008 09:25 AM
Author: Will Tomlinson Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:58204#316056 SQL server 2000. I have two columns - startdate and enddate, why would this not return a record if the startdate and enddate are the same. ex. 12/01/2008 for both. AND GETDATE() >= couponstartdate and GETDATE() <= couponenddate Is there a better way to write this? I need it to return a record. It also seems to not pull the record unless the enddate is one day after the day I want it to expire. Thanks, Will
<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

May 24, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
     1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31     

Designer, Developer and mobile workflow conference