Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases 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 June 4th, 2003, 05:33 AM
Registered User
 
Join Date: Jun 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c_capo
Default date select

Hello,

I write my date as string in a table ('dd/mm/yyyy').
Now I wont to do a select but it has to do with a where clause on this date.

Can I do this:
sDate = DateAdd("m","-3",date()) select data from last 3 months

"SELECT * FROM tblCV WHERE cv_date <='" & dDate & "'"

I think it works better if I change the date format in:
yyyy/mm/dd since I save this as string in the database.


What I need to do:
- select cv's between a certain date
- select cv's from last 3 months

My date is written as a string in the database.


Please an opinion or solution

Thanks



:: soulcreation.com ::
 
Old June 4th, 2003, 12:46 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 158
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to NotNowJohn
Default

The best soultion is to change column's data type to datetime. Then, you can use SQL operator BETWEEN for the first criteria, and be sure that operators > and < compare values properly...



...but the Soon is eclipsed by the Moon
 
Old June 5th, 2003, 01:03 AM
Registered User
 
Join Date: Jun 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you must use a string for the date then

YYYY/MM/DD

is the way to go as it should sort correctly if leading zeros for months and days are enforced by your application and you may be able to construct a query to with greater thans or less thans to return what you need.

sDate = DATEADD("m",-3,date())
strSQL = "SELECT * FROM tblcv WHERE CAST(cv_date as datetime) <= '" & sdate & "'"


The ASP above might create the SQL string you need if you are going against a SQL server... I couldn't test it though

When using a database that supports a date data type I would definitely look at redefining the column, especially when you want to perform date math.

Hope this helped
HR
 
Old June 5th, 2003, 09:25 AM
Registered User
 
Join Date: Jun 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c_capo
Default

thanks for the answers.

I cannot change the field type.
The application was initially designed and programmed by someone else.
I am hired to make changes, add fields and search possibillities etc.

I will change the string format in yyyy/mm/dd which is the best format since you can easily do a SORT and also a BETWEEN.



:: soulcreation.com ::





Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Date odezzie Classic ASP Databases 2 March 28th, 2007 04:11 PM
Select the latest date, then the lowest price. Stuart Stalker SQL Server DTS 2 October 12th, 2006 03:42 AM
XSLT and SELECT with a specfic date range pallone XSLT 15 May 8th, 2006 12:41 PM
SELECT LIKE on DATE fields borami Classic ASP Databases 2 March 16th, 2004 11:43 AM
SELECT LIKE on DATE fields borami Classic ASP Databases 0 March 16th, 2004 08:20 AM





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