Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exists this Date Function? 2

Status
Not open for further replies.

RovirozM

Technical User
Dec 9, 2009
37
MX
Hi Guys,

Do you know if there's a function that give me this information?

If I have the Date of today ( For example Getdate() ) depending of that day can I know the first day of the actual month and the last one with a function?

For example I have this: 2-Jun-2010

And I Will know this:
FirstDayMonth: 1-Jun-2010
LastDateMonth: 30-Jun-2010

Thanks!
 
Run this code:
Code:
DECLARE @Today DATETIME
SELECT @Today = CONVERT(DATETIME, CONVERT(VARCHAR(10), GETDATE(), 112))

SELECT @Today AS Today, DATEADD(day, (DATEPART(day, @Today) - 1) * -1, @Today) AS FirstDayOfMonth, DATEADD(day, -1, DATEADD(month, 1, DATEADD(day, (DATEPART(day, @Today) - 1) * -1, @Today))) AS LastDayOfMonth
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top