Question: My dataframe `df` is:

```
    Election Year   Votes   Party   Region
  0   2000           50      A       a
  1   2000           100     B       a
  2   2000           70      C       a
  3   2000           26      A       b
  4   2000           180     B       b
  5   2000           100     C       b 
  6   2000           120     A       c
  7   2000           46      B       c
  8   2000           80      C       c
  9   2005           129     A       a
  10  2005           46      B       a
  11  2005           95      C       a
  12  2005           60      A       b
  13  2005           23      B       b
  14  2005           95      C       b
  15  2005           16      A       c
  16  2005           65      B       c
  17  2005           35      C       c

```

I want to get the regions in which the two largest parties have a Vote difference of less than 50 every year. So the desired output is:

```
 Region
  a
  c

```

These are two regions where the top two parties had a Vote difference of <50 every year.

I tried to groupby using "Election Year" and "Region" and then sort the Votes in descending order. But I am unable to check if the difference between top two votes of each region in every year is less than 50.

how can I get the desired output?

Answer: 
The *set\** methods don't "convert to epoch number", they modify the date's internal time value and return the modified value. The date object is still a date.

```js
let today = new Date();
today.setHours(0,0,0,0); // Start of day
let tvToday = +today;
let tomorrow = new Date(today);
// setDate adjusts the time value and returns it
let tvTomorrow = tomorrow.setDate(tomorrow.getDate() + 1);

console.log('Today\'s date: ' + today.toDateString());
console.log('Today\'s time value: ' + tvToday);

console.log('Tomorrow\'s date: ' + tomorrow.toDateString());
console.log('Tomorrow\'s time value: ' + tvTomorrow);

// May vary from 24 by up to 1 hour depending on crossing DST boundaries
console.log('Difference in hours: ' + ((tvTomorrow - tvToday)/3.6e6)); 
```

If you want a method that adds a day and returns a new Date object, write a function, maybe named *addDays*, that takes a date and number of days to add and returns a new Date object with the days added. Lots of libraries have such functions, they're not hard to write.
Not sure if you can do that without converting. Maybe convert back after.

```js
var today = new Date();
var tomorrow = new Date(today.valueOf());

const x = tomorrow.setDate(tomorrow.getDate() + 1);
console.log(x) //epoch

const z = new Date(x)
console.log(z.toString())
```