Created
November 30, 2021 14:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getDateAgo(date, days) { | |
const copiedDate = new Date(date); | |
copiedDate.setDate(copiedDate.getDate() - days); | |
return copiedDate; | |
} | |
let date = new Date(2015, 0, 2); | |
console.log( getDateAgo(date, 1).getDate() ); // 1, (1 Jan 2015) | |
console.log( getDateAgo(date, 2).getDate() ); // 31, (31 Dec 2014) | |
console.log( getDateAgo(date, 365).getDate() ); // 2, (2 Jan 2014) | |
console.log( getDateAgo(date, 1) ); | |
console.log( getDateAgo(date, 2) ); | |
console.log( getDateAgo(date, 365) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment