Last Sunday in a month?
1 view (last 30 days)
Show older comments
Andreas Georgakakos
on 20 Feb 2018
Answered: Peter Perkins
on 20 Feb 2018
Hi there,
I am trying to identify the datetime of the last Sunday in March and October. I am aware of the nweekdate function but it requires the nth occurence of the day in that month, as an input. Any ideas would be highly appreciated.
Thank you in advance,
Andreas
0 Comments
Accepted Answer
More Answers (1)
Peter Perkins
on 20 Feb 2018
Unless you are using a version of MATLAB prior to R2014b, use datetimes for dates, not numbers:
>> d = dateshift(datetime(2018,[3 10],1,'Format','eee, dd-MMM-yyyy'),'end','month')
d =
1×2 datetime array
Sat, 31-Mar-2018 Wed, 31-Oct-2018
>> d = dateshift(d,'dayofweek','sunday','previous')
d =
1×2 datetime array
Sun, 25-Mar-2018 Sun, 28-Oct-2018
0 Comments
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!