【发布时间】:2020-03-30 16:29:55
【问题描述】:
这是我的代码和我的问题。当我运行 SQL 查询时,它不仅显示当前年份,而且显示前一年(2018 年),它显示(对于当前月份,我正在写这个),我认为我转换日期的方式有问题?任何帮助将不胜感激。
<?
$fdaymonth = (new DateTime('first day of this month'))->format('m/d/Y');
$ldaymonth = (new DateTime('last day of this month'))->format('m/d/Y');
$currmonthname = Date('F');
?>
<hr />
<p class="pull-left txt-color-blueLight">Marked in system as sold in <?=$currmonthname;?>:
<?
$query = "SELECT source,count(*) as total
FROM apps
WHERE date_sold BETWEEN '" . $fdaymonth . "' and '" . $ldaymonth . "'";
$result = mysqli_query($conn,$query) or die(mysqli_error($conn));
if (mysqli_num_rows($result)== 0) echo "<strong>Error</strong>";
// Print out result
while($row = mysqli_fetch_array($result)){
echo "<b class=\"badge bg-color-greenLight\">" . $row['total'] . "</b>";
}
?>
</p>
【问题讨论】:
-
这是什么语言? php? Python? Javascript?我不会将字符串“本月的第一天”作为构造函数的参数
-
你的后端数据库是什么,相关列是如何定义的?
-
您使用的是
mysqli_query,但语法是 SQL Server(convert带有 3 个参数)。 -
Salman A 能给我举个例子吗?那么问题出在 SQL 查询本身吗?数据库后端是 MySQL
-
是的,它是 PHP
标签: php sql date type-conversion