1i 一直在使用 html 5 的 input type="date" 并发现它非常有用。我只是想知道这是否可能:
假设我在日期选择器中选择了 1/01/2012
我想将它保存在我的数据库(mysql)上,但我希望它像这样“2012 年 1 月 1 日”
有没有办法做到这一点,怎么做?
require_once "includes/database.php";
$title=$_POST['txtTitle'];
$old_date = explode("/",$_POST['txtDate']);
$new_date = $old_date[1].' '.$old_date[0].','.$old_date[2];
$date=$new_date;
$from=$_POST['txtFrom'];
$to=$_POST['txtTo'];
$place=$_POST['txtPlace'];
$details=$_POST['txtDetails'];
$id=$_POST['txtEid'];
if($id==""){
$sql = "INSERT INTO events (event_title,event_date,event_tfrom,event_tto,event_place,event_details) VALUES (:title,:date,:from,:to,:place,:details)";
$qry = $db->prepare($sql);
$qry->execute(array(':title'=>$title,':date'=>$date,':from'=>$from,':to'=>$to,':place'=>$place,':details'=>$details));
}else{
$sql = "UPDATE events SET event_title=?, event_date=?, event_tfrom=?, event_tto=?, event_place=?, event_details=? WHERE event_id=?";
$qry = $db->prepare($sql);
$qry->execute(array($title,$date,$from,$to,$place,$details,$id));
}
echo "<script language='javascript' type='text/javascript'>alert('Successfully Saved!')</script>";
echo "<script language='javascript' type='text/javascript'>window.open('cms_events.php','_self')</script>";