[英]Getting day of the week (mon, tues, wed) based on Y:m:d format saved in database field
我有一個名為'transactions'
的數據庫表,字段'actualdate'
具有保存的每一行的日期,如2014-09-13
。
我正在使用此查詢顯示結果:
"SELECT id,actualdate, SUM(points) FROM transactions GROUP BY DAY(actualdate) ORDER BY id DESC limit 7"
然后顯示結果:
while($row = mysqli_fetch_array($result) ) {
echo "<li>";
echo $row['actualdate'];
echo " ";
echo $row['SUM(points)'];
echo "</li>";
}
是否可以根據格式設置的日期回顯每個匯總結果的星期幾?
謝謝。
是的,當然可以,在這種情況下,您可以使用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
應用:
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.