monday of previous week

633 views
Skip to first unread message

a11st4r

unread,
Aug 26, 2008, 7:44:05 AM8/26/08
to Datejs - A JavaScript Date Library
Hi,

This is a really nice library, thanks. I am trying to get hold of the
monday in the week prior to the current week. When I use
Date.today().last().monday() on a monday this gets me the last monday
which is fine, but if I am not on a monday it gets me the current
week's monday and not that of the week before. I have tried various
things out like Date.today().last().monday().add(-7) or parse("monday
before last") but it looks like I will have to do some additional
checking and extra calls to get this working. Or am I missing a nice
simple 1 statement line that would always return this for me? :)

Cheers

geoffrey.mcgill

unread,
Aug 26, 2008, 7:49:59 AM8/26/08
to Datejs - A JavaScript Date Library
Hi there,

The following should work...

Date.mon().last().mon()


Explanation: Date.mon() will return Monday of the current week,
then .last().mon() will return the week prior to that.

Hope this helps.

a11st4r

unread,
Aug 26, 2008, 7:58:20 AM8/26/08
to Datejs - A JavaScript Date Library
Hi.

Thanks for your suggestion. I am told that Date.mon and Date.monday do
not exist as functions so I could not use your sample.

I have gotten the previous monday in a more long-winded way currently
with:

Date.today().moveToDayOfWeek(1).addWeeks(-2)

This I think moves to the next Monday and then I go back 2 weeks.
Seems to do the job but I would prefer your method if it worked!

Thanks :)

geoffrey.mcgill

unread,
Aug 26, 2008, 8:02:37 AM8/26/08
to Datejs - A JavaScript Date Library
Just make sure you have the latest code from SVN. I think those
functions were added after the Alpha-1 release.

http://www.datejs.com/svn/

Hope this helps.

a11st4r

unread,
Aug 26, 2008, 8:54:53 AM8/26/08
to Datejs - A JavaScript Date Library
got it, excellent, thanks :)
Reply all
Reply to author
Forward
0 new messages