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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 date functions in sql server

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-30 : 08:00:01
nani writes "how to get first day in a month when entered any day in that month using sql server?"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-30 : 08:18:38
Select dateadd(d,1,getdate()- day(getdate()))


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-08-30 : 09:19:05
Mady's solution will get you the 1st day of the month, with the current time.

If you want midnight this may do what you want:

SELECT DateAdd(Month, DateDiff(Month, 0, getdate()), 0)

Kristen
Go to Top of Page

yoko
Starting Member

3 Posts

Posted - 2005-08-30 : 11:29:11
How can I get the Current Month and year with this formula ie August, 2005?

thanks
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-08-30 : 11:57:30
Sorry not sure what you are after;

Given that "now" is 16:54 on 30th August, 2005 do you want:

01 August 2005 16:54

01 August 2005 00:00

or "August 2005"

??

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-31 : 01:38:55
quote:
Originally posted by yoko

How can I get the Current Month and year with this formula ie August, 2005?

thanks




select datename(month, Getdate()) + ', ' + datename(year, Getdate())

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -