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
 DateDiff

Author  Topic 

sanjay5219
Posting Yak Master

240 Posts

Posted - 2010-02-11 : 05:05:41
Dear All,

I have one column DOJ in Test Table.Now i have to update one another column tenure.In Tenure data should be saved in this format.

MM.DD (2.3) means 2 month 3 days.

Please suggest.

Thanks

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-02-11 : 05:13:03
Tenure data is the different between which 2 date ? from which column ?


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

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-11 : 05:17:21
[code]UPDATE Table
SET Tenure=CAST(DATEDIFF(dd,DOJ,GETDATE())/30 AS varchar(10)) + '.' + CAST(DATEDIFF(dd,DOJ,GETDATE())%30 AS varchar(10))[/code]

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

Go to Top of Page

sanjay5219
Posting Yak Master

240 Posts

Posted - 2010-02-11 : 05:37:43
Thanks/It's done
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-11 : 05:38:24
cool

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

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-11 : 06:03:47
quote:
Originally posted by sanjay5219

Dear All,

I have one column DOJ in Test Table.Now i have to update one another column tenure.In Tenure data should be saved in this format.

MM.DD (2.3) means 2 month 3 days.

Please suggest.

Thanks


Where do you want to show formatted dates?

Madhivanan

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

rajpes
Starting Member

13 Posts

Posted - 2010-02-11 : 06:52:03
update tenture set new_column =cast(datepart(month,DOJ) as varchar(2))+'.'+cast(datepart(day,DOJ) as varchar(2))
Go to Top of Page
   

- Advertisement -