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 :: detecting screen width in jquery 
Javascript :: google script for loop 
Javascript :: react bootstrap styles not working 
Javascript :: js get current time minutes 
Javascript :: moment today date 
Javascript :: convert english number to bangla javascript 
Javascript :: space between react native 
Javascript :: discord.js cooldown 
Javascript :: fontawsome icon size react element 
Javascript :: Appium press Enter on android with js 
Javascript :: × MUI: makeStyles is not longer exported from @mui/material/styles. You have to import it from @mui/styles. 
Javascript :: typescript read url parameters 
Javascript :: javascript store array in localstorage 
Javascript :: regex validate money 
Javascript :: angular rebuild 
Javascript :: js remove dollar sign from string 
Javascript :: react native text wrap 
Javascript :: javascript voice reader 
Javascript :: unable to resolve path to module eslint 
Javascript :: angular ng serve with custom port 
Javascript :: on change jquery 
Javascript :: javascript get all array elements except last 
Javascript :: listen prop change vuejs 
Javascript :: jquery form serialized data 
Javascript :: get the current url javascript 
Javascript :: country code regex 
Javascript :: Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source. 
Javascript :: how to check if file upload is empty jquery 
Javascript :: fetch await 
Javascript :: cdnjs smeantic ui 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =