Created
December 28, 2021 14:01
-
-
Save bilal-08/b463cfc8eea071e4febd20aa62942d5b to your computer and use it in GitHub Desktop.
This file contains 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 getPreviousdate(date){ | |
const [day,month,year] = date.split('-'); | |
const today = new Date(year,month - 1,day) | |
const milliseconds = today.getTime() - 86400000 | |
const d2 = new Date(milliseconds); | |
const Previousdate = d2.toLocaleDateString(['ban', 'id']) | |
.replace(/[\/]/g,'-'); | |
//replaces '/' with '-' , comment above line if you want the regular date format | |
console.log(Previousdate) | |
return Previousdate | |
} | |
// Accepts day-month-year / returns the same format | |
getPreviousdate('01-01-2021') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tell me what you think and let me know if you know other methods!