Converting time from 24-hour to 12-hour format with AM/PM in MATLAB tables?

18 views (last 30 days)
Hi,
I am working with MATLAB tables and trying to convert a column vector containing time information from 24-hour format to 12-hour format with AM/PM. I have tried several ways of doing it as written in MATLAB questions/help but none seems to work.
Attached is the screenshot of a dummy dataset. The original column is how my data look like and I want to covert it like Converted column. Any help would be highly appreciated.

Accepted Answer

Walter Roberson
Walter Roberson on 12 Sep 2022
T = datetime('now') + hours(-15:-9).'
T = 7×1 datetime array
11-Sep-2022 19:04:31 11-Sep-2022 20:04:31 11-Sep-2022 21:04:31 11-Sep-2022 22:04:31 11-Sep-2022 23:04:31 12-Sep-2022 00:04:31 12-Sep-2022 01:04:31
T.Format = 'hh:mm:ss a'
T = 7×1 datetime array
07:04:31 PM 08:04:31 PM 09:04:31 PM 10:04:31 PM 11:04:31 PM 12:04:31 AM 01:04:31 AM

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!