Reply to topic
Compare a Date field in Access to ASP date
superjew1


Joined: 22 Jul 2004
Posts: 12
Location: NJ
Reply with quote
I am having trouble comparing a date in the database to any of ASP date functions.

Page one. i have a select that populates from a database of all the dates on the column.

Page two. i pass in the date from page one as a dim and i want to do a SQL like: "Select * from [table] where oDate = "'& date() &'"

it gives me a data type mismatch error.

any solutions???

thanks for all your help.
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1031
Location: Felton, Delaware
Reply with quote
Have you tried wrapping it in single quotes?

Code:
strSQL = "Select * from [table] where oDate = '" & date(Now()) & "'"


maybe even this will work:

Code:
strSQL = "Select * from [table] where oDate LIKE '" & Now() & "'"


Mind you, this returns the system date, so if you're in a time zone other than where the server is (or how it's set) then you should probably adjust your time accordingly.
tried it.
superjew1


Joined: 22 Jul 2004
Posts: 12
Location: NJ
Reply with quote
I tried . What i really need to know is there a way to make something that is a dim a date field. that way it will compare them becuase they are the same field. i also tried making the field a varChar in access, but then it wouldnt order it properly.
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1031
Location: Felton, Delaware
Reply with quote
Nah a date field in access should be datetime. Nothing else.

You know, what you could probably do is use the Date function in SQL...

Code:
SELECT * FROM tblTable WHERE oDate=GETDATE()
bobclingan
Forum Regular

Joined: 16 Sep 2004
Posts: 271
Location: Abingdon, MD
Reply with quote
I seem to remember having to use pound signs (#) around the date for something I was doing with Access.
andrew


Joined: 14 Jul 2004
Posts: 1
Reply with quote
In MS SQL I often compare dates with datadiff function. I have never personally used ms access for web applications but it is a good bet that it has this function as well. Within an asp page the syntax would look like this:

Code:

<% obj.open "SELECT * FROM target_table WHERE (DateDiff(day, target_Column, '" & Date & "') = 0)" %>


That would return all the results from the target table where the 'target_column' is dated for the current day according the server where the page is hosted. Another date could easily be feed in to the query by changing the '& Date &' to a string formatted like mm/dd/yyyy.

Again I am sorry to say I have never tried this with MS Access only SQL but it may be worth a shot.


Complete DateDiff Syntax:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctdatediff.asp
Josh
Forum Regular

Joined: 01 Apr 2004
Posts: 1031
Location: Felton, Delaware
Reply with quote
I didn't think DateDiff applied to what he was asking... he wasn't looking to pull a "range" of dates, just dates pertaining to the given day. I think bobum offered you a step in the right direction... wrapping your date in pound signs (#).
Compare a Date field in Access to ASP date
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic