Click here to Skip to main content
15,887,300 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
my code can only view past week and next week. but I want to see all the previous and future weeks. Thus the two features will function as calendar functions.

will be really grateful if you respond with codes

here are my cods

JavaScript
function PreviousWeek() {
    function getPreviousWeekDay(now, d) {
        var x = ((d) - now.getDay());
        now.setDate(now.getDate() + x - 7);
        return now;
    }

var now = new Date();

var previousMonday = getPreviousWeekDay(new Date(), 1);
var previousTusday = getPreviousWeekDay(new Date(), 2);
var previousWensday = getPreviousWeekDay(new Date(), 3);
var previousThirsday = getPreviousWeekDay(new Date(), 4);
var previousFriday = getPreviousWeekDay(new Date(), 5);
var previousSaturday = getPreviousWeekDay(new Date(), 6);
var previousSunday = getPreviousWeekDay(new Date(), 7);

$('#lbl1').html(previousMonday.format('yyyy-MM-dd'));
$('#lbl2').html(previousTusday.format('yyyy-MM-dd'));
$('#lbl3').html(previousWensday.format('yyyy-MM-dd'));
$('#lbl4').html(previousThirsday.format('yyyy-MM-dd'));
$('#lbl5').html(previousFriday.format('yyyy-MM-dd'));
$('#lbl6').html(previousSaturday.format('yyyy-MM-dd'));
$('#lbl7').html(previousSunday.format('yyyy-MM-dd'));


function NextWeek()
{
    function getNextWeekDay(now, d)
    {
        var x = ((d) - now.getDay());
        now.setDate(now.getDate() + x + 7);
        return now;
    }

var now = new Date();

var nextMonday = getNextWeekDay(new Date(), 1);
var nextTusday = getNextWeekDay(new Date(), 2);
var nextWensday = getNextWeekDay(new Date(), 3);
var nextThirsday = getNextWeekDay(new Date(), 4);
var nextFriday = getNextWeekDay(new Date(), 5);
var nextSaturday = getNextWeekDay(new Date(), 6);
var nextSunday = getNextWeekDay(new Date(), 7);

$('#lbl1').html(nextMonday.format('yyyy-MM-dd'))
$('#lbl2').html(nextTusday.format('yyyy-MM-dd'))
$('#lbl3').html(nextWensday.format('yyyy-MM-dd'))
$('#lbl4').html(nextThirsday.format('yyyy-MM-dd'))
$('#lbl5').html(nextFriday.format('yyyy-MM-dd'))
$('#lbl6').html(nextSaturday.format('yyyy-MM-dd'))
$('#lbl7').html(nextSunday.format('yyyy-MM-dd'))
Posted
Comments
Pradip R 1-May-15 6:05am    
You might find something with moment.js plugin. It is very good plugin when it comes to date and time. Refer this documentation: http://momentjs.com/docs/
That is because you are getting only one. You should loop for past weeks and future weeks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900