Skip to content

Instantly share code, notes, and snippets.

@Risyandi
Last active May 5, 2023 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Risyandi/7820dbb09c59a3def34066e0b87d9586 to your computer and use it in GitHub Desktop.
Save Risyandi/7820dbb09c59a3def34066e0b87d9586 to your computer and use it in GitHub Desktop.
generateID using javascript
function generateID() {
const date = new Date();
const day = ("0" + date.getDate()).slice(-2);
const month = ("0" + (date.getMonth() + 1)).slice(-2);
const year = date.getFullYear().toString().substr(-2);
const random = Math.random().toString(36).substring(2, 6).toUpperCase();
return `INV-DOL-${day}${month}${year}-${random}`;
}
const newID = generateID();
console.log(newID);
// example result : INV-DOL-050523-9JPO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment