开发者

Combining the date in order to insert it to the database

开发者 https://www.devze.com 2022-12-18 12:05 出处:网络
I need to combine day, month and year in PHP in order to insert it to MySQL database. How I\'ll combine the day, the month and the y开发者_StackOverflow社区ear? I\'m choosing the date from a drop down

I need to combine day, month and year in PHP in order to insert it to MySQL database. How I'll combine the day, the month and the y开发者_StackOverflow社区ear? I'm choosing the date from a drop down menu.


MySQL expects the date in this format: yyyy-mm-dd, so if you are using seprate drop downs for day, month and year you can cocatenate them like so:

$date = $_POST['year'] . '-' . $_POST['month'] . '-' . $_POST['day'];

If your form's method is 'get' instead of 'post', then substitute $_POST with $_GET in the code. Also make sure the value is set correctly for days 1 to 9 as 01 to 09 and you use a two digit value - the same for month. I.e.

<select name="month">
   <option value="01">1</option>
   ...
</select>


If the drop-downs have numeric values, you can just use ordinary date adding functions.

0

精彩评论

暂无评论...
验证码 换一张
取 消