简体   繁体   English

根据数据库字段中保存的Y:m:d格式获取星期几(星期一,星期二,星期三)

[英]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.

相关问题 格式为m / d / y时,如何检查数据库中星期几? - How to check database for day of the week when format is in m/d/y? 从日期(dmY)格式中查找PHP中一周中的天数 - Finding the number of the day in a week in PHP from a date ( d-m-Y ) format 将日期转换为日期名称,例如 Mon、Tue、Wed - Convert date to day name e.g. Mon, Tue, Wed 将从数据库YMD提取的标准日期格式更改为DMY - Change standard date format fetched from database Y-M-D into D-M-Y 以dmY格式显示MySQL数据库中的日期 - Displaying date from MySQL database in the d-m-Y format 如何在PHP中以DMY格式按Mysql数据库中的日期列显示并基于它进行搜索 - How Can I Display By Date Column From Mysql Database In D-M-Y Format in PHP And Make Search Based on it 如何在PHP中将上个月的第一天转换为Ymd格式 - How to convert last month first day to Y-m-d format in php 将日期以PHP m / d / y格式设置为Ymd? - Format Date in PHP m/d/y to Y-m-d? 为什么DateTime :: createFromFormat(&#39;dmY H:i A&#39;,$ date)-&gt; format(&#39;dm-Y&#39;)将日期更改为下午1点后的第二天? - Why does DateTime::createFromFormat('d-m-Y H:i A', $date)->format('d-m-Y') change the date to the following day after 1pm? 我应该如何将任何类型的日期格式从数据库转换为这种格式“d/m/Y”? - How should i convert any type of date format from database to this format "d/m/Y "?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM