Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." 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 Basics 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 July 7th, 2003, 12:01 AM
Authorized User
 
Join Date: Jun 2003
Location: Melbourne, Victoria, Australia.
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdaustin Send a message via Yahoo to tdaustin
Default Convert String Date to Date for a SQL Query

Hi all,

Im having a problem with a SQL Query. Im try to do a search of invoices between a date range specified by the the user.

They fill out 3 form fields DayFrom, MonthFrom and YearFrom and the same for DayTo, MonthTo and YearTo.

I then join these values. eg.

BeforeDate = DayFrom & "/" & MonthFrom & "/" & YearFrom
and
ToDate = DayTo & "/" & MonthTo & "/" & YearTo

When i query the db i get error
Data type mismatch in criteria expression

How can i convert the string to compare to a Date field in my DB.

My SQL is like this for a starter.

strSQL = "SELECT * FROM tblJobs WHERE JobPerson LIKE '%"&SearchCriteria&"%' AND JobDate = '"&BeforeDate&"'"

Thanks in advance


TDA
__________________
TDA
 
Old July 7th, 2003, 12:13 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Tim,
Not sure if this is the problem but the best way to use dates in SQL Server I have found is yyyy/mm/dd which takes out the confusion with the northern hemisphere which uses mm/dd/yyyy instead of our dd/mm/yyyy.
Can you post a response.write for the string strSQL before the database access.

Rod
 
Old July 7th, 2003, 12:55 AM
Authorized User
 
Join Date: Jun 2003
Location: Melbourne, Victoria, Australia.
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdaustin Send a message via Yahoo to tdaustin
Default

Hi Rod,

Im using a access database and when i add the date to the DB field (Field: JobDate DataType: Date/Time) it excepts it fine.
Code example
objRS("JobDate") = JobDay & "/" & JobMonth & "/" & JobYear

However when i try to compare to this value using the same form format as entering via a form to the db it rejects my SQL query.

Thanks for your help

TDA
 
Old July 7th, 2003, 01:09 AM
Friend of Wrox
Points: 2,376, Level: 20
Points: 2,376, Level: 20 Points: 2,376, Level: 20 Points: 2,376, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Australia.
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Sorry Tim,

I'm not very familliar with Access DB details, but what your trying to do sounds fine.
Have you checked the strSQL string to be sure the variables are holding the right stuff?

Rod
 
Old July 7th, 2003, 06:01 PM
Authorized User
 
Join Date: Jun 2003
Location: Melbourne, Victoria, Australia.
Posts: 90
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to tdaustin Send a message via Yahoo to tdaustin
Default

Yeah I solved and tested the problem by Testing that the DataType was Date by IsDate(BeforeDate) after using the CDate Function to convert it.

All Seems Well

TDA




Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert string to Date rprasad012 ASP.NET 1.0 and 1.1 Basics 1 March 19th, 2008 07:07 AM
how to convert string to date tgopal Javascript 2 March 18th, 2008 03:33 AM
convert string to date collie SQL Server 2000 4 March 15th, 2007 03:50 PM
convert string to date deeptibg SQL Server DTS 1 December 22nd, 2005 08:47 PM
Convert Part of String to Date twsinc Access VBA 6 October 20th, 2004 03:31 PM





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