How can I convert a JSON date with timezone to a SQL Server datetime?

Tarzan

I saved the output of a JSON object in a CSV file. I want to import the data into SQL Server. I have tried to cast the JSON date column to a SQL Server datetime data type.

select cast('2009-06-18T16:44:20+0000' as datetime)

This causes an error to be raised: Conversion failed when converting date and/or time from character string.

How can I convert a JSON date with timezone to a SQL Server datetime?

Paweł Dyl

As far as I know, SQL Server recognizes timezone with colon. You have to reformat timezone part as follows:

SELECT CONVERT(datetime2, STUFF('2009-06-18T16:44:20+0000', 23, 0, ':'))

According to MSDN ISO 8601 has YYYY-MM-DDThh:mm:ss[.nnnnnnn][{+|-}hh:mm] format.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I convert a string into a DateTime for a specific timezone, preserving the date exactly is it comes for that timezone?

How to convert string contain timezone to datetime sql server

How can I convert all DateTime properties to a different TimeZone in a collection?

How can I batch convert timezone of DATETIME entries?

How I can convert a DateTime with timezone to a Unix TimeStamp ? C#

How can I convert this query result to date format (SQL Server)

How to convert date string with timezone to datetime in python

How to convert string date with timezone to datetime?

How to convert Date to timezone aware datetime in polars

How can I convert date string to data in javascript in different timezone?

How can I convert including timezone date in swift?

How can I convert a specific string date to date or datetime in Spark?

How to convert a Date in specific Timezone and send to server

How can I truncate a datetime in SQL Server?

SQL Server DateTime with timezone

How can I convert a date format in SQL?

How to convert SQL Server date into C# DateTime

Oracle how to convert Timestamp with any Timezone, to Date with database server Timezone

How can I convert an Integer datatype columns value into datetime in SQL Server

How can I group by a datetime column with timezone?

how can i compare instances of timezone and datetime

How can I convert year, date, month to datetime?

How can I convert a Timestamp into either Date or DateTime object?

In python pandas, how can I convert this formatted date string to datetime

How can I convert an XML date to a valid datetime?

How can I convert a specific string format to date or datetime in Spark?

How can I convert a time string with region/city timezone format to UTC using pytz and datetime libraries?

How do I parse a json/javascript date with timezone to C# DateTime?

sql server convert string representing datetime to date