datetime error in 2025a version

9 views (last 30 days)
Hossein
Hossein on 6 Jun 2025
Commented: Star Strider on 7 Jun 2025
Hi,
I have been using a program using 2019a version with no problem. After upgrading to 2025a, the datetime function is giving me problems. What has changed since 2019a?. Here is the code
Raw_Table.Date = datetime(My.Date, 'convertfrom', 'datestr', 'format', 'eee yyyy MMM dd');
where
My.Date
ans =
3×1 datetime array
2025-06-04
2025-06-05
2025-06-06
I get the following error:
Error using datetime (line 198)
Input data must be one numeric matrix when converting from a different date/time representation.
Thanks.

Answers (2)

Star Strider
Star Strider on 7 Jun 2025
I may be missing something, however it appears that 'My.Date' is already a datetime array.
You do not need to do anything to it, however it is relatively easy to change its format.
Try smething like this --
My.Date = datetime([2025 06 04; 2025 06 05; 2025 06 06], Format='yyyy-MM-dd');
My.Date % Original
ans = 3×1 datetime array
2025-06-04 2025-06-05 2025-06-06
My.Date.Format='eee yyyy MMM dd';
My.Date % New Format
ans = 3×1 datetime array
Wed 2025 Jun 04 Thu 2025 Jun 05 Fri 2025 Jun 06
.
  2 Comments
Hossein
Hossein on 7 Jun 2025
Edited: Hossein on 7 Jun 2025
You are correct. I did not notice it. The program downloads data using an API and in 2019a, the downloaded dates used to be in a different format. So, something has changed between 2019a and 2025a, but my problem has gone away by commenting out that line. Thanks

Sign in to comment.


Walter Roberson
Walter Roberson on 7 Jun 2025
'convertfrom' 'datestr' is not a supported option
If you have date strings then you leave out the 'convertfrom' option.
But it does not appear that you have date strings. You have datetime objects. There are no versions of datetime() that accept datetime objects.
If you want to change the Format then just do
Raw_Table.Date = My.Date;
Raw_Table.Date.Format = 'eee yyyy MMM dd';

Products


Release

R2025a

Community Treasure Hunt

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

Start Hunting!