0

Is there any way to change the date format in Matlab without first converting to a number?

Here is a pseducode example of what I mean:

timeString = '23/04/2016';
newFormat1 = 'yy-mm-dd';
myPseudoFun(timeString, newFormat1)

ans =

16-04-23


newFormat2 = 'dd mmm yyyy';
myPseudoFun(timeString, newFormat2)

ans =

23 Apr 2016

All help is much appreciated!

2
  • What's the problem with datestr(datenum(timeString, oldFormat), newFormat)? That's pretty much what any implementation of myPseudoFun would be doing... Commented May 19, 2016 at 13:35
  • I need to do this for, up to, 20 million elements Commented May 20, 2016 at 6:30

1 Answer 1

1

Use the datetime datatype: (Note the use of capital M's for month. Lower case m is for minutes.)

>> timeString = datetime('23/04/2016','InputFormat','dd/MM/yyyy')
timeString = 
   23-Apr-2016
>> timeString.Format = 'yy-MM-dd'
timeString = 
   16-04-23
>> timeString.Format = 'dd MMM yyyy'
timeString = 
   23 Apr 2016
Sign up to request clarification or add additional context in comments.

2 Comments

Worth noting that this data type was introduced in R2014b
Thanks @Phil Goddard. Unfortunately, this is too time consuming =/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.