You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Convert date from number to format in matllab
1 view (last 30 days)
Show older comments
I have original time and date format as mentioned below:
2/17/2020 9:48:18 AM
I did forecasting using this , and after forecasting output date in the plot appears in number format like :
43878.4085416667
How can i convert it back to original date and time format ?
9 Comments
Walter Roberson
on 31 Jan 2021
How did you do the forecasting with it?
Did you convert the date/time t numeric using datenum() ? If so, only do that if the forecasting routines do not support datetime objects, and otherwise use datetime() .
NN
on 31 Jan 2021
Edited: NN
on 31 Jan 2021
but it appears like serial numbers :i want to convert it to date and time format :i tried the below code but unable to plot since it is character array(pic attached) :If i convert it to double again it becomes NAN since it has string values:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/504903/image.png)
o=datestr(in);
S = double(out);
S1=datestr(S);
figure
plot(out)
hold on
plot(in,'.-')
hold off
Walter Roberson
on 31 Jan 2021
date_num2 = testdates + seconds(Data{:,2});
Now if possible use date_num2 in the forecasting, and plot with
plot(date_num2, in)
Walter Roberson
on 31 Jan 2021
How are you generating the date value from forecasting ?
The values near 43878.4085416667 suggest to me,
datetime(43878.4085416667, 'convertfrom', 'excel')
ans = datetime
17-Feb-2020 09:48:18
but why are you getting Excel dates at all???
Accepted Answer
Walter Roberson
on 31 Jan 2021
outd = datetime(out, 'convertfrom', 'excel');
plot(outd)
10 Comments
Walter Roberson
on 31 Jan 2021
Your code should be changed so that it does not produce Excel date numbers from the forecast. However, you are not being cooperative in identifying how it is getting Excel date numbers as output values, so I stopped caring.
Walter Roberson
on 31 Jan 2021
The first step would be to describe how you are currently doing the forecasting. Which I already asked about twice before.
Walter Roberson
on 1 Feb 2021
This is the information we, as outside observers, have so far:
- You have a datetime() vector named in
- Your results from your forecasting is named out
- Your results are in Excel date numbers
- You are using lstm forecasting.
(4) tells us that you must have created layers, and called trainNetwork(), and probably called predictAndUpdateState() https://www.mathworks.com/help/deeplearning/ug/time-series-forecasting-using-deep-learning.html
However, it does not tell us what you passed to trainNetwork(), and it does not tell us what layers you used.
So... we need to read your mind to figure that out. And when I read your mind, and your memory of what code you wrote, I figured out that your bug is in character #11 of line 7 of your code.
NN
on 5 Feb 2021
so sorry ,
i tried to do LSTM in the same way as in https://www.mathworks.com/help/deeplearning/ug/time-series-forecasting-using-deep-learning.html
Walter Roberson
on 5 Feb 2021
Edited: Walter Roberson
on 5 Feb 2021
I was right, the bug is in character #11 of line 7 of your code. (Prove me wrong!)
More Answers (0)
See Also
Categories
Find more on Calendar 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!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)