sql server - SQL Query to find the last day of the month -


i need find last day of month in following format:

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

anybody please out.

try 1 -

create function [dbo].[udf_getlastdayofmonth]  (     @date datetime ) returns datetime begin      return dateadd(d, -1, dateadd(m, datediff(m, 0, @date) + 1, 0))  end 

query:

declare @date datetime select @date = '2013-05-31 15:04:10.027'  select dateadd(d, -1, dateadd(m, datediff(m, 0, @date) + 1, 0)) 

output:

----------------------- 2013-05-31 00:00:00.000 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -