SQL Query to find the last day of the month

前端 未结 14 1533
太阳男子
太阳男子 2020-11-27 04:40

I need to find the last day of a month in the following format:

\"2013-05-31 00:00:00:000\"

Anybody please help out.

相关标签:
14条回答
  • 2020-11-27 05:28
    declare @date date=getdate()
    declare @st_date date,@end_dt date
    set @st_date=convert(varchar(5),year(@date))+'-'+convert(varchar(5),month(@date))+'-01'
    set @end_dt=DATEADD(day,-1, DATEADD(month,1,@st_date))
    ---------**************--------------
    select @st_date as [START DATE],@end_dt AS [END DATE]
    
    0 讨论(0)
  • 2020-11-27 05:28
    Select DATEADD(DAY, -(DAY(DATEADD(MONTH, 1, GETDATE()))),DATEADD(MONTH, 1, GETDATE()))
    

    This works great in T-sql ..

    Replace the GETDATE() of the query with your column name .

    0 讨论(0)
提交回复
热议问题