SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 1st, 2003, 07:24 AM
davidagnew davidagnew is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 6 davidagnew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Comparing Dates in SQL

Hello! can anyone please help or had smiliar problems?

I have an Access database with a field named 'bid_close_date' (data type = 'Date/Time' - General Date: DD/MM/YYYY HH:MM:SS) in a table named tblplayers.

I am running the following Query, using NOW() - which I was hopeing would return all the players from tblplayers whose bid_close_date is less than NOW().

SQL = "SELECT * FROM tblPlayers WHERE bid_close_date > # " & NOW &" # ;"

HOWEVER! The SQL only seems to be looking at the first part of the Date i.e. DD and not the rest of the date string. i.e. MM/YYYY HH:MM:SS

N.B. when I compare dates in VBscript it recognises the dates and the comparisons works. i.e. return the desired result.

<%
IF Now() > rs("Bid_close_date") THEN

Response.Write("THIS AUCTION CLOSED etc...")

End If
%>

If anyone has any suggestions I would be most grateful.

David

Reply With Quote
  #2  
Old October 7th, 2003, 12:19 PM
m_lazor m_lazor is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Luxembourg
Posts: 156 m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
I wonder how you can get any result at all. Now() is precise to the second and therefore, you should only be able to get a record that was inserted in the very moment of issuing the select query (or later????? beware the ">"!!!)

Second point is that you are in a MS Windows world. They are formatting dates back and forth (behind the curtain) without showing you what is going on. Access puts even more formatting to that.

Next is the question: is your bid_close_date a date/time field? I.e. does it understand dates?

Reply With Quote
  #3  
Old October 9th, 2003, 07:27 AM
lvramani lvramani is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 14 lvramani User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post

Dear Friend,
At the very beginning i would like to say that there a mistake in your query.
SQL = "SELECT * FROM tblPlayers WHERE bid_close_date > # " & NOW &" # ;"


It must be some thing like

SQL = "SELECT * FROM tblPlayers WHERE bid_close_date < date()

Condition Apply
--------------------

You must go to the design view of the table tblPlayer and click on the bid_close_date field.

Down on the General Tab page you have a property called Format. Just select the Short Date from the Drop Down and save the changes to the date base.

Now u can start working
Best Wishes !!!!

Reply With Quote
  #4  
Old December 26th, 2003, 08:02 AM
yogesh17980 yogesh17980 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 1 yogesh17980 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 sec
Reputation Power: 0
Dear David,

Your Query...
SQL = "SELECT * FROM tblPlayers WHERE bid_close_date > # " & NOW &" # ;"
...is correct, nothing is wrong in that. But as you said that VB Script does the thing correctly, and not the SQL, it is bcoz, the VBScript run on the client(local) machine only and the SQL runs on the server. So the proble is the NOW function, that assumes the Server's NOW date and not your machines. So to work your query perfectly, you need your PC's system date equal to your server's system date.
Suggestion on it are always welcome.
Yogesh Patil

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Comparing Dates in SQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT