Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Truncate Function

Author  Topic 

rds207
Posting Yak Master

198 Posts

Posted - 2010-02-12 : 17:53:01
Hi

Could anybody please let me know functions in sql server 2008 to perform below operation

- returns the date of the Monday of that week.
- returns the date truncated to the 1st day of the month
- returns the date truncated to the 1st day of the quarter

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-02-12 : 18:16:43
[code]SELECT
DATEADD(WEEK, DATEDIFF(WEEK, 0, CURRENT_TIMESTAMP), 0) AS MondayOfCurrentWeek,
DATEADD(MONTH, DATEDIFF(MONTH, 0, CURRENT_TIMESTAMP), 0) AS FistOfCurrentMonth,
DATEADD(QUARTER, DATEDIFF(QUARTER, 0, CURRENT_TIMESTAMP), 0) AS FirstOfCurrentQuarter[/code]
Go to Top of Page

rds207
Posting Yak Master

198 Posts

Posted - 2010-02-12 : 19:05:34
Thank you so much

Could you please let me know i can in this format too?

CURRENT_TIMESTAMP's (month)- 'Mon-yy'
CURRENT_TIMESTAMP's quarter - 'Mon-yy'


quote:
Originally posted by Lamprey

SELECT 
DATEADD(WEEK, DATEDIFF(WEEK, 0, CURRENT_TIMESTAMP), 0) AS MondayOfCurrentWeek,
DATEADD(MONTH, DATEDIFF(MONTH, 0, CURRENT_TIMESTAMP), 0) AS FistOfCurrentMonth,
DATEADD(QUARTER, DATEDIFF(QUARTER, 0, CURRENT_TIMESTAMP), 0) AS FirstOfCurrentQuarter



Go to Top of Page
   

- Advertisement -