I am working with an audit table that has an nvarchar(255) column that can have many types of different data values based on another field value. For one of those other field values I'm trying to convert the nvarchar value to a datetime value. Here is an example of what I'm trying to do:
declare @d nvarchar(255) = '2022-06-01'
SET @d = CONVERT(datetime,@d)
select @d;
The value returned is: Jun 1 2022 12:00AM
What I am trying to get is: 06/01/2022 12:00AM
I did try the code below but I'm missing the 4 digit year and I want the seconds removed but it's a lot closer than the example above:
declare @d nvarchar(255) = '2022-06-01'
SET @d = CONVERT(varchar,CONVERT(datetime,@d),22);
select @d;
The value returned is: 06/01/22 12:00:00 AM
What I am trying to get is: 06/01/2022 12:00AM
Is there a way to accomplish that? Any help/direction would be greatly appreciated. Thank you.