In reference to my last "tutorial" about the date selector generator (here)...I'm going to show you how you can get a unix timestamp from this and then play around with the date the user gave you.
So, assuming you call the function like this:
Then wherever the form is directed to go, you would collect the information from the submission like this:
Okay, so now you have this fancy unix timestamp. A unix timestamp is a count in seconds since the Unix epoch (January 1, 1970). PHP has a function that can manipulate this and get some super awesome info from them using this. For example, to get their age, you might do this:
$age = date("Y") - date("Y", $birthdaytime);
This gets the current year and the year of their birth from the timestamp and subtracts the latter from the former getting the user's age. Cool, huh?
To get their birthday back from the timestamp, you might do this:
echo date('m-d-y', $birthdaytime);
This will take the timestamp and format it into month-day-year.
You can see more ways to manipulate the date @ PHP's documentation:
http://www.php.net/manual/en/function.date.php
Hope this helps 🙂
So, assuming you call the function like this:
Code:
<?php generate_date_selector("birth", "Birthday", 2014, 1920); ?>
Then wherever the form is directed to go, you would collect the information from the submission like this:
Code:
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
//form with method post was submitted
$birthdaytime = strtotime($_POST['birthyear']."-".$_POST['birthmonth']."-".$_POST['birthday']);
// ^ convert "2014-1-1" (January 1, 2014) to 1388534400 (a timestamp)
}
?>
Okay, so now you have this fancy unix timestamp. A unix timestamp is a count in seconds since the Unix epoch (January 1, 1970). PHP has a function that can manipulate this and get some super awesome info from them using this. For example, to get their age, you might do this:
$age = date("Y") - date("Y", $birthdaytime);
This gets the current year and the year of their birth from the timestamp and subtracts the latter from the former getting the user's age. Cool, huh?
To get their birthday back from the timestamp, you might do this:
echo date('m-d-y', $birthdaytime);
This will take the timestamp and format it into month-day-year.
You can see more ways to manipulate the date @ PHP's documentation:
http://www.php.net/manual/en/function.date.php
Hope this helps 🙂







