Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Get First Day and last day of week javascript

var curr = new Date; // get current date
var first = curr.getDate() - curr.getDay(); // First day is the day of the month - the day of the week
var last = first + 6; // last day is the first day + 6

var firstday = new Date(curr.setDate(first)).toUTCString();
var lastday = new Date(curr.setDate(last)).toUTCString();

firstday
"Sun, 06 Mar 2011 12:25:40 GMT"
lastday
"Sat, 12 Mar 2011 12:25:40 GMT"
Comment

get first day of the week of a given date javascript js

let wDate = new Date();
let dDay = wDate.getDay() > 0 ? wDate.getDay() : 7;
let first = wDate.getDate() - dDay + 1;
let firstDayWeek = new Date(wDate.setDate(first));
let lastDayWeek = new Date(wDate.setDate(firstDayWeek.getDate()+6));
console.log(firstDayWeek.toLocaleDateString());
console.log(lastDayWeek.toLocaleDateString());
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript ::  
::  
::  
::  
:: redux dev tools 
::  
::  
::  
::  
::  
Javascript ::  
::  
::  
::  
:: how to use url parameters in react 
::  
::  
::  
::  
::  
Javascript ::  
::  
::  
Javascript ::  
::  
::  
::  
::  
::  
::  
ADD CONTENT
Topic
Content
Source link
Name
6+3 =