Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 18th, 2005, 08:57 AM
Authorized User
 
Join Date: Jul 2004
Posts: 16
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to meichmann Send a message via AIM to meichmann Send a message via Yahoo to meichmann
Default Getting Dates in SQL

Hello Everyone!
     I hope someone can help because i've been banging my head on my desk about this one.

I have a database with a list of Countywide sponsored events. I would like to retrieve a list of events from todays date up to two weeks from now (i.e. if todays date is jan 1, 2005, i would like to retrieve a list of events from jan 1 - jan 15th.)

is there any way to pull the current date from the server and just add 14 days to it using the BETWEEN statement or do i have to write a script in .ASP to declare variables and concantenate it in my SQL Statement?

Any and all help would be greatly appreciated!

Thank you!

Matt

 
Old April 18th, 2005, 09:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

how about something like
... WHERE (<<datefield>> BETWEEN GETDATE() AND DATEADD(d, 14, GETDATE()))
 
Old April 18th, 2005, 10:42 AM
Authorized User
 
Join Date: Jul 2004
Posts: 16
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to meichmann Send a message via AIM to meichmann Send a message via Yahoo to meichmann
Default

ok, here is my sql statement:

"SELECT * FROM tblCountyEvent WHERE StartDate BETWEEN " & Date() & " AND " & DateAdd("d",14,Date()) & " ORDER BY DisplayDate"


and here's the result when i do a response.write in .asp:
SELECT * FROM tblCountyEvent WHERE StartDate BETWEEN 4/18/2005 AND 5/2/2005 ORDER BY DisplayDate"

Now the page loads, but no results come up and the table names are correct.

should i have singles quotes around the date fields? if i try that then i get an error - type mismatch

any ideas?

 
Old April 18th, 2005, 10:56 AM
Authorized User
 
Join Date: Jul 2004
Posts: 16
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to meichmann Send a message via AIM to meichmann Send a message via Yahoo to meichmann
Default

I found the error. All I had to do was add hashmarks to the SQL Statement:

"SELECT * FROM tblCountyEvent WHERE StartDate BETWEEN #" & Date() & "# AND #" & DateAdd("d",14,Date()) & "# ORDER BY DisplayDate"

now the listing works correctly. thank you for your help!

 
Old April 18th, 2005, 10:57 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes - You do need single quotes around your dates.


 
Old April 18th, 2005, 10:58 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

huh....you are using MS Access..?


this is a SQL Server forum






Similar Threads
Thread Thread Starter Forum Replies Last Post
help with SQL dates Byock SQL Server 2000 1 March 23rd, 2006 12:58 PM
SQL dates - Problem malecumbria Classic ASP Databases 4 February 16th, 2005 01:18 PM
SQL dates in American lic023 Access VBA 4 July 8th, 2004 03:06 AM
sql for searching in between given dates reshmisworld Classic ASP Databases 1 July 26th, 2003 10:23 AM
International Dates in SQL owain SQL Language 2 June 13th, 2003 03:12 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.