Extracting Date and Time from time() function in PHP

Sometime ago the time() function in PHP seems to confuse me of not knowing how to use it but I was just told it calls up current time and date.

Well, my research later gave me something when I was accessing all functions my Dreamweaver suggests for me. I found the getdate() function and saw example where the time() function was used in it,  I then felt glad because I now know how to use it! :)

You can extract everything about date and time from the time function using the getdate() function.

Run this


<?php
print_r(getdate(time()));
?>

The output should be something like this


<?php
Array ( [seconds] => 43 [minutes] => 0 [hours] => 1 [mday] => 10 [wday] => 0 [mon] => 11 [year] => 2013 [yday] => 313 [weekday] => Sunday [month] => November [0] => 1384041643 )
?>

Which is an array….

How we can work with this?
Assuming I want to get the seconds, I will use this


<?php
$time
= getdate(time());
echo $time['seconds'];
//As listed here Array ( [seconds] => 43 [minutes] => 0 [hours] => 1 [mday] => 10 [wday] => 0 [mon] => 11 [year] => 2013 [yday] => 313 [weekday] => Sunday [month] => November [0] => 1384041643 )
?>

You can go on and add more!  :D

Hope it helps…

Posted in: