WHERE with month

User avatar
sal21
PlatinumLounger
Posts: 4353
Joined: 26 Apr 2010, 17:36

WHERE with month

Post by sal21 »

In filed Data_cont i have a sequence of dates, similar:

01/06/2014
02/06/2014
05/02/2013


i need to exctrac only the value of month 6 and year 2014, i use this but dont work:-(

WHERE Month([DATA_CONT])='6'

User avatar
HansV
Administrator
Posts: 78448
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: WHERE with month

Post by HansV »

You can use

WHERE Year([DATA_CONT])=2014 AND Month([DATA_CONT])=6

There are no single or double quotes around 2014 or around 6 because they are numbers, not text values. Another method would be

WHERE Format([DATA_CONT],'yyyymm')='201406'

Here we do need quotes around 201406 since the Format function returns a text value.
Best wishes,
Hans