Date function use to select record not more than date in month

Hi,
what is the date function I can use to select records which no more than date in the month. For example I run a select statement

select * from recordtable where date <30:04:2011 23:59:59:000'

But using a date function I want when I assign the where clause sql will automatically detect end date for each month.
motioneyeAsked:
Who is Participating?
 
Rajkumar GsConnect With a Mentor Software EngineerCommented:

select * from recordtable where date < DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))
0
 
cfEngineersConnect With a Mentor Commented:
select * from recordtable where GetDate() < '30:04:2011 23:59:59:000'
0
 
Rajkumar GsConnect With a Mentor Software EngineerCommented:
0
 
Ephraim WangoyaCommented:
use this
declare @LastOfMonth DateTime
set @LastOfMonth = DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE())+1,0))
elect * from recordtable where date <= LastOfMonth

Open in new window

0
 
Alpesh PatelConnect With a Mentor Assistant ConsultantCommented:
select * from recordtable where date < dateadd(day,-1,dateadd(month,1,convert(varchar,YEAR(GETDATE())) + '-' + right('0' + convert (varchar,MONTH(GETDATE())),2) + '-01' ))
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.