当前位置:网站首页>PHP获取本周所有日期或者最近七天所有日期
PHP获取本周所有日期或者最近七天所有日期
2022-07-28 11:24:00 【历史老师-】
本篇文章主要为大家介绍下php如何获取本周的所有日期,或者最近七天的所有日期。希望可以帮助到有需要的朋友
获取本周所有日期:
/**
* 获取本周所有日期
*/
function get_week($time = '', $format='Y-m-d'){
$time = $time != '' ? $time : time();
//获取当前周几
$week = date('w', $time);
$date = [];
for ($i=1; $i<=7; $i++){
$date[$i] = date($format ,strtotime( '+' . $i-$week .' days', $time));
}
return $date;
}
执行结果:
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
)
获取最近七天日期:
/**
* 获取最近七天所有日期
*/
function get_weeks($time = '', $format='Y-m-d'){
$time = $time != '' ? $time : time();
//组合数据
$date = [];
for ($i=1; $i<=7; $i++){
$date[$i] = date($format ,strtotime( '+' . $i-7 .' days', $time));
}
return $date;
}
执行结果:
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
)边栏推荐
猜你喜欢

STL の 概念及其应用

Service Workers让网站动态加载Webp图片

Hcip rip comprehensive experiment

Deployment and use of Minio distributed object storage

LyScript 获取上一条与下一条指令

Use Baidu PaddlePaddle easydl to complete garbage classification

Unity 一键替换场景中的物体

中国业务型CDP白皮书 | 爱分析报告

Develop your own NPM package from 0

Distributed system (III) construction of distributed transaction service
随机推荐
[leetcode] 6. invert binary tree
Business visualization - make your flowchart'run'(4. Actual business scenario test)
Loongarch Godson architecture document collection
What is WordPress
Service workers let the website dynamically load webp pictures
14、用户web层服务(二)
Some knowledge concepts
Distributed system (III) construction of distributed transaction service
Reasons and solutions for moving the first column to the last column in El table
什么是WordPress
tolua之wrap文件的原理与使用
Unity one key replacement of objects in the scene
程序的存储态与运行态
15、用户web层服务(三)
DNS series (III): how to avoid DNS spoofing
[leetcode] 8. binary search · binary search
[diary of supplementary questions] [2022 Niuke summer multi school 2] l-link with level editor I
P5472 [noi2019] douzhudi (expectation, Mathematics)
2022.07.07 summer training personal qualifying (II)
玩转诗词-领略古诗文之美