how to generate unique id in php based on current data and time?

user1518659 picture user1518659 · Aug 28, 2012 · Viewed 23.2k times · Source

I need to generate a unique ID in php based on current date and time to keep a log of when i am running code. i.e. every time i run the code it should be able to generate a unique id based on current date and time.

Hope I am clear with my ques. How to do that?

Answer

amitchhajer picture amitchhajer · Aug 28, 2012

Using time() to create sortable unique id's

Concatenating strings will also further randomize your desired result and still keep it sortable. manual here

$uniqueId= time().'-'.mt_rand();