We now have a youtube channel. Subscribe!

PHP | microtime() Function

PHP microtime() Function

Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP microtime() Function.

PHP microtime() function returns current Unix timestamp with microseconds. By default, this function returns a string value which contains microseconds and seconds which is separated by space (msec sec).


Following below is the syntax to use this function -


Parameter Details

Sr.NoParameter & Description


This is a boolean value which is used to specify whether the result should be a floating point value or not. If you pass the boolean value true as a parameter, this function returns result as floating point value.

Return Value

This PHP function returns the current Unix timestamp. By default this returns a string value in the form msec sec. If you pass the boolean value true as a parameter to this function, then it returns the current time in seconds since Unix epoch which is accurate to the nearest microseconds.

PHP Version

This function was first introduced as part of the core PHP v 4 and, it works with all the later versions.


Following example illustrates the usage of the PHP microtime() function -

   $time = microtime();


When the above code is executed, it will produce the following result -

0.01174200 1606064533


Let us try to set the get_as_float value to true -

   $time = gettimeofday(true);    


When the above code is executed, it will produce the following result -



Try the following example -

   $time_start = microtime(true);
   $time_end = microtime(true);
   $time = $time_end - $time_start;
   echo "Did nothing in $time seconds\n";


When the above code is executed, it will produce the following result -

Did nothing in 0.00095605850219727 seconds

Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the PHP mktime() Function.

Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain