Tamil
Tamil

Reputation: 1203

Convert 12 hours to 24 hours from varchar column in SQL Server

In my existing SQL Server database, there is a column like this:

Now I want to convert it into 24 hours format. i.e., it should convert to 14.30

When I tried this:

SELECT
    CONVERT(VARCHAR(8), meeting_time, 1) 
FROM 
    group_info 
WHERE 
    MGI_Id = 1

It will return the same value which stored in this column. When I tried with converting it into time or datetime, it throws exception.

Can anyone please help me!

Thanks in advance.

Upvotes: 0

Views: 343

Answers (1)

James Z
James Z

Reputation: 12318

This should work:

select convert(time, stuff(meeting_time, 6,  1, ' '))

Not sure if it works with all locales / languages, so you should check that first.

This assumes that your date is always in the same format, that the extra : is in the 6th character.

Upvotes: 2

Related Questions