---
# System prepended metadata

title: Date

---

# Date

![](https://i.imgur.com/YtjTRt5.png)

```javascript=
function startOfWeek(date) {
  var dateObject = new Date(date);

  var myDate = dateObject.getDate(); // date
  console.log(myDate);

  var myDay = dateObject.getDay(); // which day of week
  console.log(myDay);

  // for india
  var weekFirstDay = dateObject.getDay() === 0 ? -6 : 1;
  // if 0 mean sunday then -6
  // else +1
  console.log(weekFirstDay)


  var weekStart = myDate - myDay + weekFirstDay;
  console.log(weekStart);
  // var diff = date.getDate() - date.getDay() + (date.getDay() === 0 ? -6 : 1);
  
  // return new Date(date.setDate(diff));
 
}

// console.log(new Date(1, 0, 1))
// console.log(new Date(199999, 11, 31))
console.log('Sunday');
startOfWeek(new Date(2020, 5, 28));

console.log('Saturday');
startOfWeek(new Date());

console.log('Friday');
startOfWeek(new Date(2020, 5, 26));

console.log('Thursday');
startOfWeek(new Date(2020, 5, 25));

console.log('Wednesday');
startOfWeek(new Date(2020, 5, 24));

console.log('Tuesday');
startOfWeek(new Date(2020, 5, 23));

console.log('Monday');
startOfWeek(new Date(2020, 5, 22));

console.log('Sunday');
startOfWeek(new Date(2020, 5, 21));


```

![](https://i.imgur.com/DMfxckU.png)
