Get date unix format from user’s selected value in dropdown list

I’m pretty new to php and I am trying to get the value of user’s selected value from 3 different fields in dropdown (day, month, year) of their birthday into unix format. I know there is an easier way of using datepicker, but I would like to know how this way works. So far the following are my coding

Register.php

<form name="registrationForm" method="post" id="registrationForm" class="registrationForm" action="processRegister.php">
<tr class="birthday-select">
<td>&nbsp;</td>
<td class='input1'>
<?php
    if($user_profile['birthday']){
        $month = substr($user_profile['birthday'], 0, 2);
        $day = substr($user_profile['birthday'], 3, 2);
        $year = substr($user_profile['birthday'], 6);
        $date = DateTime::createFromFormat('m/d/Y', $user_profile["birthday"]);
        $birthday = floatval($date->format('U')) * 1000;
        $string_time = sprintf('%.0f', $birthday);
        }
?>
<input type="hidden" name="birthday" id="birthday" value="<?php echo $birthday; ?>">
<select name="birthday_month" class="month" id="bdayMonth">
    <option value="1" <?php if($month == "01"){ echo 'selected'; } ?>>January</option>
    <option value="2" <?php if($month == "02"){ echo 'selected'; } ?>>February</option>
    <option value="3" <?php if($month == "03"){ echo 'selected'; } ?>>March</option>
    <option value="4" <?php if($month == "04"){ echo 'selected'; } ?>>April</option>
    <option value="5" <?php if($month == "05"){ echo 'selected'; } ?>>May</option>
    <option value="6" <?php if($month == "06"){ echo 'selected'; } ?>>June</option>
    <option value="7" <?php if($month == "07"){ echo 'selected'; } ?>>July</option>
    <option value="8" <?php if($month == "08"){ echo 'selected'; } ?>>August</option>
    <option value="9" <?php if($month == "09"){ echo 'selected'; } ?>>September</option>
    <option value="10" <?php if($month == "10"){ echo 'selected'; } ?>>October</option>
    <option value="11" <?php if($month == "11"){ echo 'selected'; } ?>>November</option>
    <option value="12" <?php if($month == "12"){ echo 'selected'; } ?>>December</option>
</select> </td>
<td class='input1'>
<select name="birthday_day" class="day" id="bdayDay"><?php
    for($i = 1; $i <= 31; $i++){
        if(intval($day) == $i){
            echo '<option value="' . $i. '" selected>' . $i . '</option>';
        }else{
            echo '<option value="' . $i. '">' . $i . '</option>';
        }
    }
?></select>
<select name="birthday_year" class="year" id="bdayYear"><?php
    for($i = intval(date("Y")); $i > 1950; $i--){
        if(intval($year) == $i){
            echo '<option value="' . $i. '" selected>' . $i . '</option>';
        }else{
            echo '<option value="' . $i. '">' . $i . '</option>';
        }
    }
?></select>
</td>
</tr>
<button class="greybtn" type="submit" id="submitButton">Submit</button>

processRegister.php

<?php
session_start ();

include_once ('ajax-helper/functions.php');
include ('ajax-helper/php-header.php');

$fields = array (
 'emailAddress' => $_POST["emailAddress"],
 'projectId' => $PROJECT_ID,
 'password' => $_POST["regPassword"],
 'firstName' => $_POST["fname"],
 'lastName' => $_POST["lname"],
 'dob' => (float)$_POST["date"],
 'gender' => $_POST["gender"]
);
  print_r($fields);
?>


Source: unix

Leave a Reply