Skip to content
Advertisement

how to auto generate id like AB22020001 in nodejs

i want auto generate id like “DC” + yaer + mounth + 4 digit in nodejs.

I am using node js to create an api to connect to the database which I use phpmyadmin I want to create an id like AB22020001 But now all I can do is create an ID like AB2202. I don’t know how to make the number after. My ID consists of 2 letters, last 2 digits of the year and month, and the other 4 digits run from 0001 to 9999. When a new month starts, the last 4 digits start counting at 00001 again.

in my code

JavaScript

Advertisement

Answer

Not sure if this is your exact requirement, It will increment the ID series according to your need, and will reset to “0001” once the month changes. but you didn’t tell what happens if counter reaches “9999” in same month.

JavaScript
Advertisement