Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php SQL文本列保存日期。如何转换以从文本中获取实际日期?_Php_Sql_Date_Type Conversion - Fatal编程技术网

Php SQL文本列保存日期。如何转换以从文本中获取实际日期?

Php SQL文本列保存日期。如何转换以从文本中获取实际日期?,php,sql,date,type-conversion,Php,Sql,Date,Type Conversion,这是我的代码和我的问题。当我运行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'); $cu

这是我的代码和我的问题。当我运行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>


在系统中标记为销售地点:

试试这个:
CAST($fdaymonth作为日期)和CAST($ldaymonth作为日期)

我最后添加了一个新列,并将文本列日期转换为日期列,以便更轻松地转换。date_Sald列是一个文本列,但实际日期为DD/MM/YYYY格式,这导致了冲突。现在它是一个日期格式的SQL列,我可以得到我想要的结果了。谢谢大家。

这是什么语言?PHP?pythonJavascript?我没有任何东西将字符串“本月第一天”作为构造函数的参数。你的后端数据库是什么,相关列是如何定义的?你使用的是
mysqli\u query
,但语法是SQL Server(
convert
,带有3个参数)。Salman a你能给我举个例子吗?那么问题是SQL查询本身?数据库后端是mysqlyes,它是PHPSadly,当添加到我的SQL语句时,它不会显示任何结果