Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting string with microseconds to DATE

I get a string as input from an application that is supposed to be a date. For some asinine reason the developers of the application decided provide precision to the microsecond. Well, actually, to the tenth of a microsecond.

The string is in the format: 2014-08-15T17:38:22.2930000

Before they changed this input format I was using the following to convert the date.

select DATEADD(dd, 30, @Date)

I know I could just do a substring on the input and lop off the last 4 characters, however, I'm wondering if there is some way that I can use CONVERT to just convert the date, or if SQL just doesn't support dates with this type of precision.

like image 233
kralco626 Avatar asked Jun 04 '26 11:06

kralco626


1 Answers

Either of these should work:

SELECT CONVERT(DATE, '2014-08-15T17:38:22.2930000', 101)
SELECT CONVERT(DATETIME2, '2014-08-15T17:38:22.2930000', 101)
like image 51
How 'bout a Fresca Avatar answered Jun 07 '26 09:06

How 'bout a Fresca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!