Solved

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

Posted on 2011-09-05
6
1,088 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 142

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

773 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