gpt4 book ai didi

php - 选择日期mysql请求

转载 作者:行者123 更新时间:2023-11-30 22:00:55 24 4
gpt4 key购买 nike

我在 php 文件中有以下请求。我正在尝试以这种格式获取日期:MONTHS-currentMonth-currentYear

$sql = "SELECT DAY(ADDDATE(`dateDebutC`, `dureeC`)) AS MONTHS FROM normalW  WHERE id = '$id'";

最佳答案

如果您想在从 sql 查询返回值后格式化日期,那么您可以使用 PHP date_format() 函数。假设您将月份值存储在一个变量中,我们称它为 $date:

echo date_format($date,'Y-m-d'); // Or whatever format you want to display

要将当前月份和当前年份添加到该字符串,您可以使用 date() 函数:

$current_month = date(m); // prints current month in numeric format (01-12)
$current_year = date(Y); // prints current year as a 4-digit representation
$new_date = $date . '-' . $current_month . '-' . $current_year;

参见 https://www.w3schools.com/php/func_date_date.asp获取所有参数的列表。友情提醒,请确保您使用的是 mysqli 而不是 mysql,后者已被弃用。

关于php - 选择日期mysql请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43399239/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com