This topic is locked

SQL Query Date&Time

2/12/2009 9:05:10 AM
ASPRunnerPro General questions
M
Maurits author

Does anyone know how to create a SQL query based on the time and date in the SQL editor of ASP Runner
SELECT

a

b

c

from Details
WHERE Details.AvailDate >= Now() AND Details.EndDate <= now()
Thanks in advance
Maurits

J
joseph83 2/12/2009
SELECT

a

b

c

from Details
WHERE Details.AvailDate >= getdate() AND Details.EndDate <= getdate()


If you want to querying a time interval you can use;

WHERE Details.AvailDate >= getdate()-1 AND Details.EndDate <= getdate()+3
Admin 2/12/2009

Maurits,
it depends on what database you use.
What is your database and what error message you getting using this query?

M
Maurits author 2/12/2009

Sorry i forgot to tell...i am using an MS Access Database.

It is for a Special offers database, so it will only show the offers between to dates in the database.
It comes up with an error: Undefined function 'getdate' in expression.
Is there another way to do this?

Admin 2/12/2009

What happens when you use query with Now()?

M
Maurits author 2/12/2009

I have tried it like you said but with error message:

MS Access driver: Syntax error (missing operator) in query expression 'Details.AvailDate => now() AND Details.CloseDate =< now()'
Here is the SQL:
SELECT

a

b

c

AvailDate

CloseDate

FROM Details

WHERE Details.AvailDate => now() AND Details.CloseDate =< now()
Is there something i am doing wrong?

C
careysado 2/12/2009

When using MS Access you need to put # around your dates.
The following works in my application:
strSQL="select from spschedule where sDate=#" & rstmpDates("sDate") & "# AND S_IDNumber = " & SESSION("_spcalendar_OwnerID") & " ORDER BY scheduleID asc"
You may need to setup a variable equal to the Now() value first.
strDate1 = Now()

strDate2 = Now() + 3
strSQL = "SELECT
FROM Details WHERE Details.AvailDate => #" & strDate1 & "# AND Details.CloseDate =< #" & strDate2 &"#"
Hope this helps!!
Carey

I have tried it like you said but with error message:

MS Access driver: Syntax error (missing operator) in query expression 'Details.AvailDate => now() AND Details.CloseDate =< now()'
Here is the SQL:
SELECT

a

b

c

AvailDate

CloseDate

FROM Details

WHERE Details.AvailDate => now() AND Details.CloseDate =< now()
Is there something i am doing wrong?

D
dlangham 2/12/2009

I have tried it like you said but with error message:

MS Access driver: Syntax error (missing operator) in query expression 'Details.AvailDate => now() AND Details.CloseDate =< now()'
Here is the SQL:
SELECT

a

b

c

AvailDate

CloseDate

FROM Details

WHERE Details.AvailDate => now() AND Details.CloseDate =< now()
Is there something i am doing wrong?


Try this below, see my additions and changes in BOLD:
SELECT

a

b

c

AvailDate

CloseDate

FROM Details

WHERE Details.AvailDate >= now()-1 AND Details.CloseDate <= now()-1