Blog of a Filipino Developer about C#, VB.NET, ASP.NET, Java, PHP, SQL Server, MySql and Oracle RSS 2.0
# Thursday, March 03, 2005

Here are some useful T-SQL code snippets that you can uses for manipulating date.

--calculates the first day of the month
select DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)

--calculates the first day of the year
select DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)

--calculates the first day of the quater
select DATEADD(qq, DATEDIFF(qq,0,getdate()), 0)

--calculates the first monday of the month
select DATEADD(wk, DATEDIFF(wk,0,dateadd(dd,6-datepart(day,getdate()),getdate())), 0)

--calculates the last day of the prior month
select dateadd(ms,-3,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0))

--calculates the last day of the prior year
select dateadd(ms,-3,DATEADD(yy, DATEDIFF(yy,0,getdate()), 0))

--calculates the last day of the current year
select dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate() )+1, 0))

--calculates the monday of the current week
select DATEADD(wk, DATEDIFF(wk,0,getdate()), 0)

--calculates the yesterdays date
select DATEADD(dd, DATEDIFF(dd,0,getdate()), -1)

Thursday, March 03, 2005 11:14:00 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
SQL
Tracked by:
"re:Tutorial Galore!" (绝缘电阻测试仪) [Trackback]
"Cash Loans" (Cash Loans) [Trackback]
"Viagra" (Viagra) [Trackback]
"Health Insurance" (Health Insurance) [Trackback]
"Payday Loan" (Payday Loan) [Trackback]
"xenical" (xenical) [Trackback]
Archive
<March 2005>
SunMonTueWedThuFriSat
272812345
6789101112
13141516171819
20212223242526
272829303112
3456789
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Keith Rull
Sign In
Statistics
Total Posts: 271
This Year: 0
This Month: 0
This Week: 0
Comments: 182
Themes
Pick a theme:
All Content © 2010, Keith Rull
DasBlog theme 'Business' created by Christoph De Baene (delarou)