Good day everyone! This is another tutorial for all PHP programmers especially those who are beginning their web sites. This would be a small but helpfull knowledge for you.
So now, we will be learning on using the getdate() function in PHP.
The getdate() is another determining function in PHP that you might find very useful. The codes below is only the prototype of this function:
[php]array getdate([int timestamp])[/php]
It will takes an optional timestamp as a parameter and returns an array representing the parts of that date and time: Below are the Array Key-Value Pairs from the getdate() function:
seconds – seconds, numeric
minutes – minutes, numeric
hours – hours, numeric
mday – day of the month, numeric
wday – day of the week, numeric
mon – month, numeric
year – year, numeric
yday – day of the year, numeric
weekday – day of the week, full-text format
month – month, full-text format
0 – timestamp, numeric
After you have these parts in an array, you can easily process them into any required format. The 0 element in the array (the timestamp) might seem useless, but if you call getdate() without parameter, it will give you the current timestamp.
By using the getdate() function, copy the following codes:
[php]<?php $today = $getdate();
print_r($today);?>[/php]
The codes above produces something similar to the following output:
Array(Array( [seconds] => 45 [minutes] =>6 [hours] => 20 [mday] => 14 [wday] => 3 [mon] => 3 [year] => 2017 [yday] => 72 [weekday] => Wednesday [month] => June [0] => 1173917205)
That’s all.
If you have questions regarding this tutorial entitled as “Using the getdate() function in PHP” feel free to ask us by commenting below or visit on our contact page. Thank you.