Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using DatePart("",) in a SQL statement for Access

Status
Not open for further replies.

FateFirst

Programmer
Apr 15, 2002
212
GB
Hi.

Quickly just chucking together a SQL statement to pull out some data for a friend. He has an access database and the field in particular is a 'date/time' field. The format of the data looks like this: '28/03/2006 22:10:38'.

I quickly chucked onto my ASP page a SQL statement using DATEPART, so it looks something like:
Code:
SELECT field_id, field_date
FROM table
WHERE (DATEPART(""yyyy"", timesheet_start_datetime) = '" & Year(Now()) & "' AND DATEPART(""m"", timesheet_start_datetime) = '" & Month(Now()) & "' AND DATEPART(""d"", timesheet_start_datetime) = '" & Day(Now()) & "')

I receive the error 'Too few parameters. Expected 3.'.

Any other recommendations or have I just made a SQL syntax error?

Thanks :)

- FateFirst
 
Oops....

'timesheet_start_datetime' should actually be 'field_date' but i forgot to change that. I was trying to rename some stuff quickly to make it more presentable :p

- FateFirst
 
response.write the SQL statement to your screen and copy paste it into access. trouble shoot syntax there and then you will have a better idea of what is not coming out correct


General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
Yea, forgot to mention I had done that already. Sorry ;)

Works perfectly in Access. If I remove that part of the WHERE the statement works fine on my ASP page.

This is why im slightly confused :)

- FateFirst
 
Solved!

Instead of using:

DATEPART(""YEAR"",field_date)

I used:

DATEPART('YEAR',field_date)

:D

- FateFirst
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top