Issue with extract and convert of date field

I am required to find the time when SQL Service was shut down ungracefully. There is nothing in the event viewer or the SQL Logs till it restarts.


I am extracting date from this statement:
The previous system shutdown at 1:30:21 PM on ‎3/‎29/‎2017 was unexpected.
I am able to get the date via extraction and it coverts it to datetime using powershell.
But when I insert that datetime into a sql table it gives the following error:

Msg 241, Level 16, State 1, Line 18
Conversion failed when converting date and/or time from character string.

By opening the string in UltraEdit for Hexa characters, I get to see this:
1:30:21 PM on ‎3/‎29/‎2017

I suspect this is the reason for its failure
the characters ‎. Not sure how to overcome this.

Any help is welcome

  • So, you are discovering the data and copying and paster from you extraction
    back into SQL or are you saying you are using PoSH to insert the data back
    into SQL?

    Since you know the string, you can just use -replace on the string to rid of
    those chars.

    $DateString = '‎3/‎29/‎2017'
    $DateString -replace ('‎','')
Reply Children