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
 General SQL Server Forums
 New to SQL Server Programming
 change char string to a date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

allan8964
Posting Yak Master

249 Posts

Posted - 10/12/2013 :  12:27:48  Show Profile  Reply with Quote
Hi there,

To change string '24.04.2013' (Apr. 24, 2013 format of dd-mm-yyyy) into a date in format of mm-dd-yyyy, what's the easiest way?
Thanks in advance.

Edited by - allan8964 on 10/12/2013 12:37:25

madhivanan
Premature Yak Congratulator

India
22765 Posts

Posted - 10/12/2013 :  12:40:52  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote

declare @date varchar(12)
set @date='24.04.2013'
select convert(char(10),convert(datetime,@date,103),110)

But this is really not needed if you store datetime values in proper datetime datatype and leave formation at front end application

Madhivanan

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

allan8964
Posting Yak Master

249 Posts

Posted - 10/12/2013 :  13:01:31  Show Profile  Reply with Quote
Ok, turn it into British date then make it string in US way. Cool!
The data are imported from SSIS package as string and saved in a varchar column, that's why it needs format changed.
Thanks madhivanan!

Edited by - allan8964 on 10/12/2013 13:02:55
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 10/12/2013 :  13:53:09  Show Profile  Reply with Quote
quote:
Originally posted by allan8964

Ok, turn it into British date then make it string in US way. Cool!
The data are imported from SSIS package as string and saved in a varchar column, that's why it needs format changed.
Thanks madhivanan!


then you should be fixing this in ssis and bringing them as dates itself. that will save you lot of convertion issues

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

allan8964
Posting Yak Master

249 Posts

Posted - 10/12/2013 :  14:05:13  Show Profile  Reply with Quote
Agree. Visakh16. But it's a global corporate and different team charge each other for those kind of changes! Project manager won't pay for that.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 10/13/2013 :  01:33:20  Show Profile  Reply with Quote
quote:
Originally posted by allan8964

Agree. Visakh16. But it's a global corporate and different team charge each other for those kind of changes! Project manager won't pay for that.


Ok
but keep in mind that if date values are not coming in consistent way this may cause errors while converting.

------------------------------------------------------------------------------------------------------
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.08 seconds. Powered By: Snitz Forums 2000