Working with Dates and Times in PHP - Make my own date time
(Page 4 of 6 )
Are you satisfied now that you can show your user for the current date and time? If you do, then don't need to read this article for more. The next step is for people who need something more.
The next function that we have to understand is mktime(). This function will make your own timestamp from a given set of variables that you pass to the function.
mktime(hour, minute, second, month, date, year);
Now, I want to know in what day my birthday was on. My birth date is July 21st 1974. I'll use the mktime function like so:
$mybirthdate = mktime(0,0,0,7,21,1974);
print date("l", $mybirthdate);
Wow, I finally found out that my birthday is on Sunday. :). Now the next case I want to know is what day is 25 days from now. Let's do it this way:
$next25day = mktime(0,0,0,date("n"),date("j")+25,date("Y"));
print date("l", $next25day);
Give attention to the variables that I passed to the mktime function. I've passed date("j")+25. It means that I want to add 25 to the current date. You can figure out what it will produce.
Next: Another method >>
More PHP Articles
More By Hermawan Haryanto