Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get start date and end date of current week (week start from monday and end with sunday )

Tags:

I want to display start date and end date of current week. (week start=monday, week end=sunday) I manage to display monday.

But I'm unable to get sunday date. Please post me if anyone has solution.

like image 243
Vishnu Avatar asked Dec 05 '11 05:12

Vishnu


People also ask

How do you get the current week start date and end date in typescript?

You can also use following lines of code to get first and last date of the week: var curr = new Date; var firstday = new Date(curr. setDate(curr. getDate() - curr.

How do I display current week in HTML?

HTML input type="week"

How do I get a week start date and end date in VB net?

int NumWeeks = 30; DateTime StartDate, EndDate; DateTime BaseDate = new DateTime(2010, 1, 1); BaseDate = BaseDate. AddDays(NumWeeks * 7); StartDate = BaseDate; while (StartDate. DayOfWeek !=


1 Answers

<script>
Date.prototype.getWeek = function(start)
{
        //Calcing the starting point
    start = start || 0;
    var today = new Date(this.setHours(0, 0, 0, 0));
    var day = today.getDay() - start;
    var date = today.getDate() - day;

        // Grabbing Start/End Dates
    var StartDate = new Date(today.setDate(date));
    var EndDate = new Date(today.setDate(date + 6));
    return [StartDate, EndDate];
}

// test code
var Dates = new Date().getWeek();
alert(Dates[0].toLocaleDateString() + ' to '+ Dates[1].toLocaleDateString())
</script>

I believe this works.

like image 109
ReadWriteCode Avatar answered Oct 21 '22 01:10

ReadWriteCode