Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to get the first day of any month Expand / Collapse
Author
Message
Posted Tuesday, August 25, 2009 10:41 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Thursday, November 15, 2012 1:15 PM
Points: 14, Visits: 66
Hi Folks,

How to get the first ay of any month, Normally we will concatenate '01' TO DATE FUNTION and set 01 as the default first day of the month.bUT FOR EVERY MONTH I SHOULD GET FIRST DAY

EXAMPLE; firstday of the month is 01 with their datename(week day)
Post #777252
Posted Tuesday, August 25, 2009 11:17 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, April 19, 2012 10:25 PM
Points: 1,231, Visits: 3,483
HI,

TRY THIS

select getdate() + (1 - DAY(getdate()))
select DATENAME(weekday,(getdate() + 1 - DAY(getdate())))

Post #777264
Posted Wednesday, August 26, 2009 9:41 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 9:07 AM
Points: 11,157, Visits: 12,899
Here's a link to a blog post by Lynn Pettis that I refer to whenever I need a date routine.



Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #777622
Posted Wednesday, August 26, 2009 10:19 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 2:20 PM
Points: 3,122, Visits: 11,401
select FirstDayOfMonth = dateadd(mm,datediff(mm,0,getdate()),0)

Results:
FirstDayOfMonth 
-----------------------
2009-08-01 00:00:00.000


Post #777654
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse