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 getdate() Function.
The PHP getdate() function is used to get information about a particular date/time. It accepts an optional parameter specifying the timestamp of which you need the information about. If you have not passed any argument, then this function returns information about the current local time.
The PHP getdate() function is used to get information about a particular date/time. It accepts an optional parameter specifying the timestamp of which you need the information about. If you have not passed any argument, then this function returns information about the current local time.
Syntax
Following below is the syntax to use this function -
getdate([$timestamp])
READ: PHP | date() Function
Parameter Details
Sr.No | Parameter & Description |
---|---|
1 | timestamp (Optional)This represents the timestamp specifying the time/date about which you need the information. |
Return Value
This built-in PHP function returns an array containing the information about the given date and time.
PHP Version
This function was first introduced as part of core PHP version 4 and, it works with all the later versions.
Example1
Following example demonstrates the usage of the PHP getdate() function -
<?php $info = getdate(); print_r($info); ?>
Output
When the above code is executed, it will produce the following result -
Array ( [seconds] => 34 [minutes] => 52 [hours] => 12 [mday] => 8 [wday] => 5 [mon] => 5 [year] => 2020 [yday] => 128 [weekday] => Friday [month] => May [0] => 1588942354 )
Example2
Now, let's try passing a timestamp to this function -
<?php $timestamp = time()-(23*12*30); $info = getdate($timestamp); print_r($info); ?>
Output
When the above code is executed, it will produce the following result -
Array ( [seconds] => 29 [minutes] => 49 [hours] => 10 [mday] => 8 [wday] => 5 [mon] => 5 [year] => 2020 [yday] => 128 [weekday] => Friday [month] => May [0] => 1588934969 )
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 gettimeofday() 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.
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.