jabeen shaik
jabeen shaik

Reputation: 1

How to change the date format in comment field that has date along with comments

I am trying to change the date format in Comment field in SQL, My comments field display data some thing like this 'shaik4, jabeen4 7/2/2019 10:11:41 AM', Comments can be longer until 2000 characters followed by date , i want my date to be in 07/02/2019 format

Upvotes: 0

Views: 343

Answers (1)

Alex Desruisseau
Alex Desruisseau

Reputation: 92

select Convert(VARCHAR(23), Cast(right(Comments, 23) as Datetime), 106) as Date
FROM *Table*

Might be the trick.

First we get the right side of the comments field to grab the date and time, then we cast it to a datetime value, then we convert our datetime to the appropriate format.

You will need to replace the 23 in comments with the appropriate amount of cells away. So 05/05/2019 11:21:00.000 would be 23. Then the 106 needs to be replaced with the correctly formatted conversion. The convert part should be easy to look up with some external resources.

If this doesn't do the trick, share more info on your database type and hopefully we can work through this together. Thanks

Upvotes: 1

Related Questions