[英]Getting day of the week (mon, tues, wed) based on Y:m:d format saved in database field
I have a database table called 'transactions'
with the field 'actualdate'
that has the date of each row saved like 2014-09-13
. 我有一个名为
'transactions'
的数据库表,字段'actualdate'
具有保存的每一行的日期,如2014-09-13
。
I'm displaying the results using this query: 我正在使用此查询显示结果:
"SELECT id,actualdate, SUM(points) FROM transactions GROUP BY DAY(actualdate) ORDER BY id DESC limit 7"
Then displaying the results with: 然后显示结果:
while($row = mysqli_fetch_array($result) ) {
echo "<li>";
echo $row['actualdate'];
echo " ";
echo $row['SUM(points)'];
echo "</li>";
}
Is it possible to echo what day of the week it was for each summed result based on the date the way it's formatted? 是否可以根据格式设置的日期回显每个汇总结果的星期几?
Thanks. 谢谢。
Yes of course, you can use Datetime
in this case: 是的,当然可以,在这种情况下,您可以使用
Datetime
:
$row['actualdate'] = '2014-09-13';
$date = new DateTime($row['actualdate']);
echo $date->format('l'); // l represents Monday, Tuesday,
// in this case "Saturday"
// For three letter representations use this:
echo $date->format('D'); // Sat
Applying it: 应用:
while($row = mysqli_fetch_assoc($result) ) {
echo "<li>";
$date = new DateTime($row['actualdate']);
echo $date->format('D');
echo " ";
echo $row['SUM(points)'];
echo "</li>";
}
如果只有那一天
$day=date( 'l', strtotime($row['actualdate']) );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.