Avatar of Fred
FredFlag for United States of America

asked on 

Converting date with a Z to format 101 format

Imported excel table to sql server,  Dispatch_Date column shows as. Its data type is varchar(50) on SQL table. I am trying  to convert it to date column, 101 and a time column

2018-08-03T12:57:25Z
2018-08-03T14:58:15Z

I tried select convert(varchar(50),Dispatch_Date,101)  shows 2018-08-03T12:57:25Z,  
I tried select convert(datetime,'Dispatch_Date',101) throws error "Conversion failed when converting date and/or time from character string."
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
Fred
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Format 101 is mm/dd/yyyy.  Just CAST the value as the type you want:

SELECT CAST('2018-08-03T12:57:25Z'  AS datetime)

Avatar of Máté Farkas
Máté Farkas
Flag of Hungary image

select convert(varchar(10), cast('2018-08-03T12:57:25Z' as datetime), 101)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Fred
Fred
Flag of United States of America image

ASKER


User generated image

Scott, I appreciate your feed back. They wanted to see Dates without the T and Z format. Also Dispatch time is to be compared to Notification time, roll time, arrival time.
 
Avatar of Fred
Fred
Flag of United States of America image

ASKER

select convert(varchar(10), cast('2018-08-03T12:57:25Z' as datetime), 101), this works well for a single row only. When trying a column "Conversion failed when converting date and/or time from character string". My point is trying to set up all the columns as the customer wants and show the differences in times in a format they want and understand
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo