javascriptdatejs

check if a date falls in the last week using date.js


i use date.js for doing certain date calculations.

i am able to find if the date falls in this week, the following returns true

dateFld.between(Date.monday(), Date.friday())

but I want to check if date falls in the previous week.

i am using the following code without luck.

alert(dateFld.between(Date.last().week().monday(), Date.last().week().sunday()));

please help.


Solution

  • Sunday is the first day of the week.

    Date.last().week().monday()

    Mon Sep 07 2015 00:00:00 GMT+0100 (GMT Daylight Time) Correct

    Date.last().week().sunday()

    Sun Sep 06 2015 00:00:00 GMT+0100 (GMT Daylight Time) Incorrect

    Date.last().sunday()

    Sun Sep 13 2015 00:00:00 GMT+0100 (GMT Daylight Time) Correct