Php 将日期转换为荷兰语格式
我想在MySQL中以荷兰语格式输入日期。现在他给了我标准格式。我需要在输出列表或插入文件中更改它吗 这是我的插入代码:Php 将日期转换为荷兰语格式,php,mysql,Php,Mysql,我想在MySQL中以荷兰语格式输入日期。现在他给了我标准格式。我需要在输出列表或插入文件中更改它吗 这是我的插入代码: <?php session_start(); include '../dbh.php'; $costname = $_POST['costname']; $category = $_POST['category']; $subcategory = $_POST['subcategory']; $price = $_POST['price']; $info = $_P
<?php
session_start();
include '../dbh.php';
$costname = $_POST['costname'];
$category = $_POST['category'];
$subcategory = $_POST['subcategory'];
$price = $_POST['price'];
$info = $_POST['info'];
$costdate = $_POST['costdate']->format("d-m-Y H:i:s");
$iduser = $_SESSION['id'];
if(empty($costname)) {
header("Location: ../dashboard.php?error=emptycostname");
exit();
}
if(empty($category)) {
header("Location: ../dashboard.php?error=emptycatergory");
exit();
}
if(empty($subcategory)) {
header("Location: ../dashboard.php?error=emptysubcatergory");
exit();
}
if(empty($price)) {
header("Location: ../dashboard.php?error=emptyprice");
exit();
}
if(empty($info)) {
header("Location: ../dashboard.php?error=emptyinfo");
exit();
}
else {
$sql = "INSERT INTO costs (costname, category, subcategory, price, info, userid, costdate)
VALUES ('$costname', '$category', '$subcategory', '$price', '$info', '$iduser', '$costdate')";
$result = mysqli_query($conn, $sql);
header("Location: ../dashboard.php");
}
您可以使用MySQL的DATE\u FORMAT
函数对其进行任意格式化。以下是如何更新select查询以对其进行格式化:
$sql_costs = "SELECT *, DATE_FORMAT(costdate, '%d-%m-%Y %H:%i:%s') AS costdate FROM costs WHERE userid='".$_SESSION['id']."'";
请在此处阅读有关DATE\u格式
功能的更多信息:
请注意,您的代码容易受到SQL注入攻击,从而使您的服务器处于风险之中。请在此处阅读有关如何安全操作的更多信息:
$sql_costs = "SELECT *, DATE_FORMAT(costdate, '%d-%m-%Y %H:%i:%s') AS costdate FROM costs WHERE userid='".$_SESSION['id']."'";