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


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

8/22/2022 - Mon
Scott Pletcher

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

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

Máté Farkas

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

Open in new window

Scott Pletcher

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck

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