Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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
Reply With Quote
  #2 (permalink)  
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
Reply With Quote
  #3 (permalink)  
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
Reply With Quote
  #4 (permalink)  
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
Reply With Quote
  #5 (permalink)  
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 07:54 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.