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 2012 Forums
 Transact-SQL (2012)
 Date format conversion

Author  Topic 

djamit
Starting Member

17 Posts

Posted - 2013-07-23 : 08:51:42
Hi,

I have a table TIMECONTROL with a column StartTime.
The column has time values in format 2013-03-09 for example.
I want to convert the values of this column to a format like this 20130309.

How can I solve this problem?

Thank You

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2013-07-23 : 08:55:45
If the datatype is a character type then:
StartTime = replace(StartTime,'-','')




Too old to Rock'n'Roll too young to die.
Go to Top of Page

djamit
Starting Member

17 Posts

Posted - 2013-07-23 : 09:09:54
Can you write down the whole code please
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2013-07-23 : 09:22:14
update TIMECONTROL
set StartTime = replace(StartTime,'-','')



Too old to Rock'n'Roll too young to die.
Go to Top of Page

djamit
Starting Member

17 Posts

Posted - 2013-07-23 : 10:52:45
Thank you very much
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-07-23 : 12:36:01
Which DATATYPE is the StartTime column? If it's DATETIME/SMALLDATETIME/DATE/DATETIME2/DATETIMEOFFSET, everything is OK. Then you are using dates correctly and the hyphen is just a presentation issue; nothing to worry about.

However, if the StartTime column is VARCHAR/CHAR/NVARCHAR/NCHAR datatype, then you will have tons of problems in the future. Please consider using a proper datatype fpr handling dates.



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-24 : 01:55:18
Why cant you do this at your front end application as its just a presentation issue?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -