在我的PHP代码中,我在数据库中插入了一些数据。日期之一。我想以27-08-2016的格式显示,但我回来了1970年1月1日
这是我的代码。
<?php
include("./init.php");
if(isset($_POST['submit'])){
$post_game = $_POST['game'];
$time = strtotime($_POST['date']);
$post_date = date("d-m-Y", strtotime($time));
if($post_game==''){
echo "<script>alert('Please fill in all fields')</script>";
exit();
}
else {
$insert_game = "insert into last_game (game,date) values ('$post_game','$post_date')";
$run_posts = mysqli_query($con,$insert_game);
echo "<script>alert('Post Has been Published!')</script>";
echo "<script>window.open('index.php?last_game_details','_self')
</script>";
}
}
?>
关键是:
$post_date = date("d-m-Y", strtotime($time));
而我的PHP版本是:5.6.23
请在查询中使用Now()插入当前日期。NOW()返回当前日期和时间。
if(isset($_POST['submit'])){
$post_game = $_POST['game'];
$time = strtotime($_POST['date']);
$post_date = date("d-m-Y", strtotime($time));
if($post_game==''){
echo "<script>alert('Please fill in all fields')</script>";
exit();
}
else {
$insert_game = "insert into last_game (game,date) values ('$post_game',NOW())";
$run_posts = mysqli_query($con,$insert_game);
echo "<script>alert('Post Has been Published!')</script>";
echo "<script>window.open('index.php?last_game_details','_self')
</script>";
}
}
?>
要检索所需的日期格式,请使用php
`echo date_format($date,"Y-m-d ");`
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句