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
1 |
<pre><br /><span style="background: #ffffe8; color: #5f5035;"><?php</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #400000;">print_r</span><span style="background: #ffffe8; color: #808030;">(</span><span style="background: #ffffe8; color: #400000;">getdate</span><span style="background: #ffffe8; color: #808030;">(</span><span style="background: #ffffe8; color: #400000;">time</span><span style="background: #ffffe8; color: #808030;">(</span><span style="background: #ffffe8; color: #808030;">)</span><span style="background: #ffffe8; color: #808030;">)</span><span style="background: #ffffe8; color: #808030;">)</span><span style="background: #ffffe8; color: purple;">;</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #5f5035;">?></span><br /> |
The output should be something like this
1 |
<pre><br /><span style="background: #ffffe8; color: #5f5035;"><?php</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: black;">Array </span><span style="background: #ffffe8; color: #808030;">(</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">[</span><span style="background: #ffffe8; color: black;">seconds</span><span style="background: #ffffe8; color: #808030;">]</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: #808030;">></span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #008c00;">43</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">[</span><span style="background: #ffffe8; color: black;">minutes</span><span style="background: #ffffe8; color: #808030;">]</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: #808030;">></span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #008c00;">0</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">[</span><span style="background: #ffffe8; color: black;">hours</span><span style="background: #ffffe8; color: #808030;">]</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: #808030;">></span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #008c00;">1</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">[</span><span style="background: #ffffe8; color: black;">mday</span><span style="background: #ffffe8; color: #808030;">]</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: #808030;">></span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #008c00;">10</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">[</span><span style="background: #ffffe8; color: black;">wday</span><span style="background: #ffffe8; color: #808030;">]</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: #808030;">></span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #008c00;">0</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">[</span><span style="background: #ffffe8; color: black;">mon</span><span style="background: #ffffe8; color: #808030;">]</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: #808030;">></span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #008c00;">11</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">[</span><span style="background: #ffffe8; color: black;">year</span><span style="background: #ffffe8; color: #808030;">]</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: #808030;">></span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #008c00;">2013</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">[</span><span style="background: #ffffe8; color: black;">yday</span><span style="background: #ffffe8; color: #808030;">]</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: #808030;">></span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #008c00;">313</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">[</span><span style="background: #ffffe8; color: black;">weekday</span><span style="background: #ffffe8; color: #808030;">]</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: #808030;">></span><span style="background: #ffffe8; color: black;"> Sunday </span><span style="background: #ffffe8; color: #808030;">[</span><span style="background: #ffffe8; color: black;">month</span><span style="background: #ffffe8; color: #808030;">]</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: #808030;">></span><span style="background: #ffffe8; color: black;"> November </span><span style="background: #ffffe8; color: #808030;">[</span><span style="background: #ffffe8; color: #008c00;">0</span><span style="background: #ffffe8; color: #808030;">]</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: #808030;">></span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #008c00;">1384041643</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #808030;">)</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #5f5035;">?></span><br /> |
Which is an array….
How we can work with this?
Assuming I want to get the seconds, I will use this
1 |
<pre><br /><span style="background: #ffffe8; color: #5f5035;"><?php</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #797997;">$time</span><span style="background: #ffffe8; color: black;"> </span><br /><span style="background: #ffffe8; color: #808030;">=</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #400000;">getdate</span><span style="background: #ffffe8; color: #808030;">(</span><span style="background: #ffffe8; color: #400000;">time</span><span style="background: #ffffe8; color: #808030;">(</span><span style="background: #ffffe8; color: #808030;">)</span><span style="background: #ffffe8; color: #808030;">)</span><span style="background: #ffffe8; color: purple;">;</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: maroon; font-weight: bold;">echo</span><span style="background: #ffffe8; color: black;"> </span><span style="background: #ffffe8; color: #797997;">$time</span><span style="background: #ffffe8; color: #808030;">[</span><span style="background: #ffffe8; color: #0000e6;">'seconds'</span><span style="background: #ffffe8; color: #808030;">]</span><span style="background: #ffffe8; color: purple;">;</span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: dimgrey;">//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 ) </span><span style="background: #ffffe8; color: black;"></span><br /><span style="background: #ffffe8; color: #5f5035;">?></span><br /> |
You can go on and add more!
Hope it helps…