那么, 我在数据库中用分钟和秒保存日期。
我想检查来自my db = to date today
的日期。
我读到了这个,我不知道如何在Date_format
中使用
也许是因为我的Date
是varchar(255)..
感谢帮助(:
编辑:
全部感谢(:
答案 0 :(得分:0)
当您在varchar
中找到您的日期时,您只需要简单的转换。您的查询应该是:
SELECT DATE_FORMAT('2015-08-21 12:35:15', '%Y-%M-%d %H:%i');
输出
2015-August-21 12:35
答案 1 :(得分:0)
你走了:
$dbdate = '8/21/2015 11:16:12 AM'; //add your database date here
$dt = new DateTime($dbdate);
$date = $dt->format('Y-m-d');
$today = date("Y-m-d"); //get current date
//now compare your dates
if($date == $today)
{
}
答案 2 :(得分:0)
您需要一个日期格式的日期,如时间戳,以便进行有效的搜索。
使用此格式,您可以进行以下搜索:
SELECT id, date FROM data WHERE date BETWEEN TIMESTAMP("2015-08-20 23:04:00") AND TIMESTAMP("2015-08-21 12:04:00")
答案 3 :(得分:0)
试试这段代码:
DATE_FORMAT(STR_TO_DATE(t.datestring, '%d/%m/%Y'), '%Y-%m-%d')
答案 4 :(得分:0)
SELECT DATE_FORMAT(date_created,'%Y /%m /%d')FROM sometable
答案 5 :(得分:0)
它没有答案,我有一个小问题..
我试过了:
$dbdate = "21/08/2015 10:13";
$select_last_vote = mysql_query("SELECT `Date` FROM `Vote` WHERE `IP` = '$ip' AND `VoteID` = '$VoteID' order by `Date` DESC LIMIT 1;");
$select_last_vote = mysql_fetch_array($select_last_vote);
$dbdate = $select_last_vote["Date"];
$takeResult = mysql_query("SELECT DATE_FORMAT(STR_TO_DATE('$dbdate', '%d/%m/%Y' ), '%d/%m/%Y') as Date ;");
$Result_date = mysql_fetch_array($takeResult);
$result_date = $Result_date["Date"];
$today = date("d/m/Y");
if($result_date == $today)
{
echo "this is today $result_date, $today";
}
else { // there is my output: You can vote! 00/00/0000
echo "You can vote! $result_date";
}
现在正在工作(:
谢谢大家!!