简体   繁体   中英

Converting String into Date from HTML Form

i collect date formats like this :

Day

<select id="DOBDay" name = "DOBDay" class="pure-input-1-4">
<option>Date Of Birth Day</option>
<option value="01">01</option>

Month

<select id="DOBMonth" name = "DOBMonth" class="pure-input-1-4">
<option>Date Of Birth Month</option>
<option value="06">06</option>

Year

<select id="DOBYear" name = "DOBYear" class="pure-input-1-4">
<option>Date Of Birth Year</option>
<option value="2000">2000</option>

After the form has been posted ,it gets collects like this :

$DOBDay = $_POST['DOBDay'];
$DOBMonth = $_POST['DOBMonth'];
$DOBYear = $_POST['DOBYear'];

How do i get this into a dateformat to be stored into a MySQL date feild. I have searched the web and cannot find this example anywhere for assistance.

Try this :

$DOBDay = '21';
$DOBMonth = '09';
$DOBYear = '1986';  
$full_date = $DOBYear.'-'.$DOBDay.'-'.$DOBMonth;
echo $full_date;`

A lot of possibilities.. mktime for example.

// if you need a timestamp
$timestamp = mktime(0,0,0,$DOBMonth, $DOBDay, $DOBYear);

// or datetime
$datetime = date("Y-m-d", $timestamp);

mysql use yyyy-mm-dd format. so you should store the value in something like :

$DOBDay = '21';
$DOBMonth = '09';
$DOBYear = '1986';  
$date = $DOBYear.'-'.$DOBMonth.'-'.$DOBDay;
echo $date;
$date= $_POST['DOBDay']."/". $_POST['DOBMonth']."/".$_POST['DOBYear'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM