SQL greater than Date

Raanan

Board Regular
Joined
May 22, 2013
Messages
122
Hi, Im hoping you can help a little..

Im trying to pull data from an Access database based on "date completed" being this year, using SQL.

Im using:
Select ....
FROM ....
WHERE [Date Completed] > '20150101'

however Im getting data mismatch.

Ive checked the Access and the date completed file is in the format Date/Time.

Ive tried different variations but cant get this to work. Any ideas?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
WHERE [Date Completed] >= #2015/01/01#

WHERE [Date Completed] >= DateSerial(2015,1,1)

WHERE CLng([Date Completed]) >= CLng(DateSerial(2105,1,1))
 
Upvote 0
It will depend a lot on the data type for the field [Date Completed]. If the datatype is date/Time then Fazza's suggestions will work.

Note: The suggestion will only work until for the current year and not past years.

I am suuing the field is a date/time data type.

If you want to be able to run this for any year then you could use:


Code:
 WHERE Year([Date Completed]) = ([enter4 digit  year])


for the current year


Code:
WHERE (Year([Date Completed]) = Year(Date()) )

Note: using Year() also remove any time (Like using Clng() )
 
Upvote 0

Forum statistics

Threads
1,215,421
Messages
6,124,806
Members
449,191
Latest member
rscraig11

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top