Convert double to DateTime format?

36 views (last 30 days)
Fredrick Neo
Fredrick Neo on 5 Jun 2018
Edited: dpb on 5 Jun 2018
How to convert numeric double types into datetime 'dd/mm/yyyy hh.mm.ss' format? Example: 20180304122050 -> become 04/03/2018 12:20:50
  6 Comments
Paolo
Paolo on 5 Jun 2018
Is OP not just asking for this?
x = num2str(20180304122050);
date = datetime(x,'InputFormat','yyyyMMddhhmmss','Format','dd/MM/yyyy hh:mm:ss');
date:
04/03/2018 12:20:50
dpb
dpb on 5 Jun 2018
Edited: dpb on 5 Jun 2018
Paolo -- looks like probably simplest solution to code; can do without the temporary even in actual implementation.
Stephen -- I meant "great" in the sense of the conversion would be trivial to code if the additional formatting strings were parsed; not so much that it is a great encoding scheme. Altho I will say I have done such things in previous life when working in constrained memory systems where the storage between 8 and 12/14 bytes was important--that's been almost 40 yr ago by now, though, granted! :)

Sign in to comment.

Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!