Last Sunday in a month?

1 vue (au cours des 30 derniers jours)
Andreas Georgakakos
Andreas Georgakakos le 20 Fév 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

Réponse acceptée

KSSV
KSSV le 20 Fév 2018
d = calendar(2013,01) ;
s = d(d(:,1)~=0,1)
s(end)

Plus de réponses (1)

Peter Perkins
Peter Perkins le 20 Fév 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

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by