Creating a unique serial number

Hello,

When looking at the serial number, the year, month, day, hour and minute are shown in the serial number to understand the date it was produced.

The last two characters are hex.

I want to show only the year, month and day to make the serial number shorter, but in such a case, is there a possibility of multiple hexes for the same day?

// Create a source date
$source_date = mktime(9, 36, 25, 2, 17, 2024); // 24 years, 02 months, 17 days, 09 hours, 36 minutes, 25 seconds

// We get date information
$year = date('y', $source_date);
$month = date('m', $source_date);
$day = date('d', $source_date);
$hour = date('H', $source_date);
$minute = date('i', $source_date);
$second = date('s', $source_date);

// Creating a two-character hexadecimal value
$hex_salt = strtoupper(str_pad(dechex($source_date % 256), 2, '0', STR_PAD_LEFT));

// We create the serial number
$serial_number = "AT{$year}{$month}{$day}{$hour}{$minute}{$hex_salt}";

// Print serial number
echo $serial_number;

The same hex repeats every 4 minutes, so we have to show the hour and minute in the serial number.

Sponsor our Newsletter | Privacy Policy | Terms of Service