Skip to content
Advertisement

How to get last Monday from a specific date

I am trying to get the date of Monday from a specific date. I try to use

JavaScript

But it’s giving me current last Monday date not from a specific date. Like I want to know the last Monday date on 2020-10-11 which is 2020-10-05

Advertisement

Answer

You can use the class DateTime to create an object at the desired date, and then modify it :

JavaScript

As pointed jspit in comments, if the current date is monday and then if this date should be returned, a simple check can be added to avoid returning the wrong date :

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement