当前位置:网站首页>PHP gets all the dates of this week or the last seven days
PHP gets all the dates of this week or the last seven days
2022-07-28 12:15:00 【History teacher-】
This article mainly introduces php How to get all the dates of this week , Or all the dates in the last seven days . Hope to help friends in need
Get all dates of the week :
/**
* Get all dates of the week
*/
function get_week($time = '', $format='Y-m-d'){
$time = $time != '' ? $time : time();
// Get the current day of the week
$week = date('w', $time);
$date = [];
for ($i=1; $i<=7; $i++){
$date[$i] = date($format ,strtotime( '+' . $i-$week .' days', $time));
}
return $date;
}
Execution results :
print_r(get_week());
Array
(
[1] => 2018-06-18
[2] => 2018-06-19
[3] => 2018-06-20
[4] => 2018-06-21
[5] => 2018-06-22
[6] => 2018-06-23
[7] => 2018-06-24
)
Get the date of the last seven days :
/**
* Get all the dates in the last seven days
*/
function get_weeks($time = '', $format='Y-m-d'){
$time = $time != '' ? $time : time();
// Combined data
$date = [];
for ($i=1; $i<=7; $i++){
$date[$i] = date($format ,strtotime( '+' . $i-7 .' days', $time));
}
return $date;
}
Execution results :
print_r(get_weeks());
Array
(
[1] => 2018-06-13
[2] => 2018-06-14
[3] => 2018-06-15
[4] => 2018-06-16
[5] => 2018-06-17
[6] => 2018-06-18
[7] => 2018-06-19
)边栏推荐
- Unity one key replacement of objects in the scene
- OsCache缓存监控刷新工具
- [real question of written examination]
- Pycharm debugging mode
- laravel表单数据验证
- A new mode of one-stop fixed asset management
- Stored state and running state of program
- Redis安装
- The game process and the underlying implementation are gradually completed
- Full resolution of the use of go native plug-ins
猜你喜欢

Untiy中控制Animation的播放速度

云原生机器学习落地难?灵雀云助力企业快速应用 MLOps

Google Earth engine (GEE) -- problems in the use of coordinate projection and reduceresolution functions in image downscaling
![[real question of written examination]](/img/3f/e061df6a2c5c92429cfd3c69cc94ce.png)
[real question of written examination]

Unity one key replacement of objects in the scene

Full analysis of seven classical regression analysis methods

The game process and the underlying implementation are gradually completed

Detailed explanation of boost official website search engine project

Several ways to bind controls --butterknife/viewbinding/databinding

Matlab sets the size of graphics window and image and the position of legend
随机推荐
"Weilai Cup" 2022 Niuke summer multi school training camp 2
Multithreading and high concurrency (III) -- source code analysis AQS principle
Laravel之缓存
Matlab sets the size of graphics window and image and the position of legend
OSCache cache monitoring Refresh Tool
Hcip (condition matching and OSPF packet related knowledge)
Stored state and running state of program
After abolishing Tencent cloud: meiyabaike won the bid of 98.3 million
Play with poetry - appreciate the beauty of ancient poetry
Unity遇坑记之 ab包卸载失败
Network communication protocol classification and IP address
Detailed explanation of boost official website search engine project
Specific functions of some multi parameter functions
缺少指令集umi2 怎么办?ptk方式安装无法进行
SQL注入 Less18(头部注入+报错注入)
tolua之wrap文件的原理与使用
Idea replication module
Simple selection sort and heap sort
Traversal and copy of files in jar package
Final modifier attribute