Get Last Week (Sun-Sat)

401 views
Skip to first unread message

AnilD

unread,
Dec 10, 2009, 12:51:21 AM12/10/09
to Datejs - A JavaScript Date Library
Hi,

Lib is really a very great work

However, I have an issue i want to get last week from Sunday to
Saturday. '1 week ago' always show last Wednesday if today is
Wednesday but i want last week from Sunday to Saturday so if today is
12-09-2009 i want to get date 11-29-2009 or say first day of last week
as start date and 12-05-2009 as end date.

Pls help me on this.

thanks.

geoffrey.mcgill

unread,
Dec 10, 2009, 1:03:00 AM12/10/09
to Datejs - A JavaScript Date Library
Hope this helps...

Example

var start = Date.parse("1 week ago");

if (!start.is().sun()) {
start.last().sun();
}

var end = start.clone().add(6).days();

console.log(start); // 2009-11-29
console.log(end); // 2009-12-05

AnilD

unread,
Dec 10, 2009, 1:08:00 AM12/10/09
to Datejs - A JavaScript Date Library
Hi,

I have use this and problem is solved.


dateStart: function() { return Date.parse('today').moveToDayOfWeek
(0).addWeeks(-2) }, dateEnd: 'previous saturday'

thanks alot....)

geoffrey.mcgill

unread,
Dec 10, 2009, 1:37:04 AM12/10/09
to Datejs - A JavaScript Date Library
Here's another slight variation on the theme...

var range = {};
var today = Date.today();

range.start = (today.is().sun() ? today : today.last().sun()).last
().sun();
range.end = range.start.clone().sat();

console.log(range.start);
console.log(range.end);

Hope this helps.
Reply all
Reply to author
Forward
0 new messages