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
 Date

Author  Topic 

siumui
Yak Posting Veteran

54 Posts

Posted - 2012-03-30 : 08:56:49
Hello all.

I want to have a new column that contains the date & time in one of the column in an existing table to be in the format of the first of that month and year.

For example:
2011-03-22
2012-04-25
2011-03-12
2011-03-22

I want to change/format/convert (not sure of word usage here) the dates from above to
3/1/2011
4/1/2012
3/1/2011
3/1/2011

I just want to change all day in any date to the first day only and still retain the month and the year in a new column in the format of mm/dd/yyyy.

Please help.

Thank you.


siumui

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-03-30 : 09:19:38
SELECT DATEADD(MONTH, DATEDIFF(MONTH, '19000101', Col1), '19000101')
FROM dbo.Table1



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

siumui
Yak Posting Veteran

54 Posts

Posted - 2012-03-30 : 11:49:22
quote:
Originally posted by SwePeso

SELECT DATEADD(MONTH, DATEDIFF(MONTH, '19000101', Col1), '19000101')
FROM dbo.Table1



N 56°04'39.26"
E 12°55'05.63"




Thank you very much!

siumui
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-30 : 17:25:52
why do you need to do formatting at sql? where are you displaying the dates?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -