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

Search cf-talk

July 04, 2009

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

Home /  Groups /  ColdFusion Talk (CF-Talk)

SQL between dates problem

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
SQL server 2000.
Will Tomlinson
12/01/08 09:25 A
If you are using MS SQL...
Dawson, Michael
12/01/08 09:50 A
>If you are using MS SQL...
Will Tomlinson
12/01/08 10:13 A
I would do something like:
Dawson, Michael
12/01/08 10:17 A
Another CFMLish option:
John M Bliss
12/01/08 10:37 A
>I would do something like:
Will Tomlinson
12/01/08 01:18 P
>If you are using MS SQL...
Will Tomlinson
12/01/08 08:08 P
Try this:
Duane Boudreau
12/01/08 09:47 A
>Try this:
Will Tomlinson
12/01/08 10:12 A
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Will Tomlinson
12/01/2008 09:25 AM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
John M Bliss
12/01/2008 09:32 AM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Will Tomlinson
12/01/2008 09:41 AM

>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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dawson, Michael
12/01/2008 09:50 AM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Will Tomlinson
12/01/2008 10:13 AM

>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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dawson, Michael
12/01/2008 10:17 AM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
John M Bliss
12/01/2008 10:37 AM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dawson, Michael
12/01/2008 10:55 AM

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))#

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Will Tomlinson
12/01/2008 01:18 PM

>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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Will Tomlinson
12/01/2008 08:08 PM

>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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dawson, Michael
12/02/2008 09:54 AM

"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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Duane Boudreau
12/01/2008 09:47 AM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Will Tomlinson
12/01/2008 10:12 AM

>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

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Will Tomlinson
12/02/2008 07:08 AM

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


<< Previous Thread Today's Threads Next Thread >>

Mailing Lists