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
 Convert date time to month?

Author  Topic 

mykel_vykers
Starting Member

5 Posts

Posted - 2010-01-28 : 00:29:39
hi, how can i able to convert this date time '2010-01-28 11:39:19.687'('YYYYMMDD Time')to month 1 (January). tnx's.

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-01-28 : 00:31:41
select datename(m,'2010-01-28 11:39:19.687')

select month('2010-01-28 11:39:19.687')

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-01-28 : 01:08:22
[code]select dateadd(month, datediff(month, 0, your_date), 0)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

mykel_vykers
Starting Member

5 Posts

Posted - 2010-01-28 : 01:11:44
sorry that is what i meant to do. i add a column MONTH using this script

ALTER TABLE sales2009
ADD Month varchar(15)

then i want that column display the month from the trans_date ('2010-01-28 11:39:19.687') convert it to number MONTH.
example.
January = 1
February = 2
March = 3
etc...

what script should i use to able to convert it and show it appear to MONTH column that i made.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-01-28 : 01:24:23
[code]datepart(month, your_date)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

mykel_vykers
Starting Member

5 Posts

Posted - 2010-01-28 : 01:38:51
tnx's got it solve this is what i use.

update sales2009
set month = MONTH(doc_date)

tnx's...
Go to Top of Page
   

- Advertisement -