SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Date format conversion
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

djamit
Starting Member

16 Posts

Posted - 07/23/2013 :  08:51:42  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 07/23/2013 :  08:55:45  Show Profile  Visit webfred's Homepage  Reply with Quote
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

16 Posts

Posted - 07/23/2013 :  09:09:54  Show Profile  Reply with Quote
Can you write down the whole code please
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 07/23/2013 :  09:22:14  Show Profile  Visit webfred's Homepage  Reply with Quote
update TIMECONTROL
set StartTime = replace(StartTime,'-','')



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

djamit
Starting Member

16 Posts

Posted - 07/23/2013 :  10:52:45  Show Profile  Reply with Quote
Thank you very much
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30242 Posts

Posted - 07/23/2013 :  12:36:01  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

India
52317 Posts

Posted - 07/24/2013 :  01:55:18  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000