Skip to content

Instantly share code, notes, and snippets.

@bilal-08
Created December 28, 2021 14:01
Show Gist options
  • Save bilal-08/b463cfc8eea071e4febd20aa62942d5b to your computer and use it in GitHub Desktop.
Save bilal-08/b463cfc8eea071e4febd20aa62942d5b to your computer and use it in GitHub Desktop.
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') 
@bilal-08
Copy link
Author

Tell me what you think and let me know if you know other methods!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment