Print Page | Close Window

Problem with dates

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=7952
Printed Date: 01 April 2026 at 1:12am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Problem with dates
Posted By: zaboss
Subject: Problem with dates
Date Posted: 09 December 2003 at 1:03am

I have a problem with dates. The sql query below should select from an mySQL db all the records for which the DataExpirarii (expiration date) value is greater than present day. Instead, it selects all of them. What is wrong?

Set RS1 = MyConn.execute("Select NumeFirma, Pozitia, DataIntroducerii, ID From Oferte  where DataExpirarii > "& Date &"  Order By DataIntroducerii DESC Limit 10")
 



-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web



Replies:
Posted By: Paul Lush
Date Posted: 09 December 2003 at 4:05am

try putting the date in ' s

eg ' " & date & " '

then make sure you have a valid date with seperators, eg "1/1/2003" or "1-1-2003" instead of "1 1 2003"

Without the actual date value (for what we know , date could contain "wibble slobber"), its hard to tell.



Posted By: zaboss
Date Posted: 09 December 2003 at 4:14am
It doesn't work with '. It triggers the "Exception occur" error. Also, Response.writing both dates shows them correct 12/3/2003 and 12/09/2003. The field in the mySQL db is a Date field.

-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web


Posted By: Paul Lush
Date Posted: 09 December 2003 at 4:27am

the ' was my mistake :(

have you tried " & cdate ( date ) & "

?

Im getting the same thing here in my msSQL server but as all of my work needs date selections, I always use BETWEEN



Posted By: Paul Lush
Date Posted: 09 December 2003 at 4:32am

This works

"Select NumeFirma, Pozitia, DataIntroducerii, ID From Oferte  where DataExpirarii  > convert(datetime , '" & date & "', 121) Order By DataIntroducerii DESC Limit 10"

there are ' in there as well



Posted By: Paul Lush
Date Posted: 09 December 2003 at 4:33am

Oh, make sure that you us US MM/DD/YYYY formatting.  That works in my msSQL, hard to tell in mySQL as I dont have it installed



Posted By: zaboss
Date Posted: 09 December 2003 at 4:34am

Nope, it doesn't work. The funny thing is that if I put there "2003-12-09" it works. I tryed to put it in a string with datePart, like in:

data =  DatePart("yyyy", Date) &"-"& DatePart("m", Date) &"-"&DatePart("d", Date) and then have the query with

"& data &"

but still does not work.



-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web


Posted By: zaboss
Date Posted: 09 December 2003 at 4:39am
The inner format for dates of MySQL is yyyy-mm-dd.

-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web


Posted By: Paul Lush
Date Posted: 09 December 2003 at 4:40am

As I dont have mySQL installed, have a look at

http://www.mysql.com/doc/en/Date_and_time_functions.html - http://www.mysql.com/doc/en/Date_and_time_functions.html



Posted By: zaboss
Date Posted: 09 December 2003 at 5:13am
Well, none of the manual suggestions works for ASP.

-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web


Posted By: zaboss
Date Posted: 09 December 2003 at 9:21am

Finaly sorted out. It should be:

<% data =  DatePart("yyyy", Date) &"-"& DatePart("m", Date) &"-"&DatePart("d", Date) %>
Set RS1 = MyConn.execute("Select NumeFirma, Pozitia, DataExpirarii, DataIntroducerii, ID From Oferte  where DataExpirarii > '"& data &"' Order By DataIntroducerii DESC Limit 10")



-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net