MATLAB: How to use retime to convert to monthly time frequency, and display the data for end of month dates

eomdatefintsMATLABretimetimeseriestimetable

I would like to alter my timetable to display end-of-month dates, rather than start-of-month dates. How can I use the retime function to achieve this?

Best Answer

The "retime" function (used with timetables) operates differently than the "tomonthly" function used with TimeSeries data, as it displays the new monthly frequency table with start-of-month datetimes rather than end-of-month datetimes.
The trick is to use the following version of retime:
TT2 = retime(TT1,newTimes,method)
and pass in the end of month date times as the variable "newTimes".
Attached is a script ("test_script.m") which demos how to create a time-series time table and how to convert them to monthly time-series and timetable respectively and the differences between the two.
The "retime" function is extensive and can be used for a variety of functions that were used to manipulate TimeSeries objects. The documentation for "retime" can be found here:
The general workflow for converting code that uses time series over to timetables can be found here:
You might have to use additional functions that operate on "datetime" arrays to get to the final result (Eg - "eomdate" in attached code).
A full list of functions that operate on "datetime" arrays can be found here: