Php Current

Php Current

PHP has many native ways to get the current timestamp and this tutorial we will walk through each of the possibilities. You can use native PHP functions such as date_timestamp_get(), time(), strtotime() in procedural style. Alternatively, you can use the DateTime class to get the current timestamp.

Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML.


Utilizing the DateTime Class

It’s more than likely that you’ve already used the DateTime class and overlooked it’s potential. It takes one function call of a DateTime instance to get a proper timestamp.

Important note: The DateTime object, when initialized, is loaded with theCurrent Timestampof execution.

let’s take a look.

  • Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Dealing with XForms Handling file uploads Using remote files Connection handling Persistent Database Connections Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication.
  • Php setcookie ('userAgent', $SERVER 'HTTPUSERAGENT', strtotime (date ('r', time ). '+2 days'));? The example above will fetch the current time in Unix Epoch, convert to your date and timezone, and covert the result to Unix Epoch again with strtotime so you can use it to set cookie expiration dates.
  • More recent versions of PHP are built with VC15 or VS16 (Visual Studio 2017 or 2019 compiler respectively) and include improvements in performance and stability. The VC15 and VS16 builds require to have the Visual C Redistributable for Visual Studio 2015-2019 x64 or x86 installed.


Php Current Epoch



Using date_timestamp_get()

If you want to use a more procedural style, then PHP has this covered also. We can call the date_create() function first which does what it says on the tin. Then we can pass the variable created into another function called date_timestamp_get(), which again, does what it says on the tin. Shout out to the guy who named these functions!

Look at the following code –




Utilizing the time() function

Another very simple way to get the current timestamp is to use the time() function. This function literally executes and returns the current timestamp.

Check out the code snippet below



This is probably by far the simplest but in a way, slightly misleading with its name.

Similarly here, we can actually use another function named microtime() which does exactly the same thing but adds on microseconds to the timestamp.

Using strtotime()

Another method is to use strtotime() passing it the ‘now’ parameter to get the current stamp. As you may know, strtotime() always parses the given context as a timestamp. So, with this in mind, the following code will be sufficient.


Php Current Directory



Yes, it is that simple.

Php Current Year


Current Php Version For Wordpress

It’s probably a shock to see how many different variations there actually is with PHP to get the current timestamp. When it comes down to actually using one of these methods, it will mostly down to preference. Hope this helps!