Solved

MS SQL 2008 R2, convert datetime in string to datetime format.

Posted on 2011-09-05
6
1,093 Views
Last Modified: 2012-06-21
I have a column with string format: dd/mm/yyyy
Now I want to convert it to datetime format: mm/dd/yyyy

How can I do?
0
Comment
Question by:JameMeck
6 Comments
 
LVL 4

Accepted Solution

by:
Sudhanshupathak earned 250 total points
ID: 36486479
0
 
LVL 22

Expert Comment

by:Thomasian
ID: 36486511
DECLARE @columnname varchar(100)
SET @columnname = '31/1/2011'
SELECT CONVERT(datetime, @columnname, 103)		--returns datetime datatype
      ,CONVERT(varchar,CONVERT(datetime, @columnname, 103),101)		--returns varchar datatype
/*Result:
2011-01-31 00:00:00.000			01/31/2011
*/

Open in new window

0
 
LVL 21

Expert Comment

by:Alpesh Patel
ID: 36486760
Cast (Datefield as datetime)
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 9

Expert Comment

by:mimran18
ID: 36486818
Try this
Declare @sdate as datetime
set @sdate='2011-12-15'  --15th December 2011

Select Convert(nvarchar(11),@sdate,101) as [mm/dd/yyyy]
,Convert(nvarchar(11),@sdate,103) as [dd/mm/yyyy] from [test]

Open in new window

0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 36488904
please see this article to work correctly with dates (and strings that look like dates):
http://www.experts-exchange.com/A_1499.html
0
 

Author Closing Comment

by:JameMeck
ID: 36507526
Thanks! I got it now.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question