Extract creation time from an UUID!

21 Mar 2014

$uuid = str_replace('-', '', $uuid);

$timeLow = hexdec(substr($uuid, 0, 8));
$timeMid = hexdec(substr($uuid, 8, 4));
$timeHi  = hexdec(substr($uuid, 13, 3));

$time = ($timeHi * pow(2, 16) + $timeMid) * pow(2, 32) + $timeLow;
$time = $time - (12219292800 * 10000000); // October 15, 1582
$time = bcdiv($time, 10000000, 7);