当前位置:网站首页>PHP 补全日期区间中缺少的日期/返回缺少的日期
PHP 补全日期区间中缺少的日期/返回缺少的日期
2022-08-09 15:09:00 【withoutfear】
<?php
/**
* PHP 补全日期区间中缺少的日期/返回缺少的日期
*/
$lists = $list = array();
$result = $db->query("SELECT id, date FROM `table_name` WHERE `areaname` = 'xxx'");
while ($r = $db->fetch_array($result)) {
$list[] = $r['date'];
$lists[] = $r;
}
# 补全日期
$newData = spd('2012-01-01', '2013-08-08');
# 缺少的日期
$difference_set_arr = array_diff($newData, $list);
echo '<pre>';
var_dump("'" . implode("','", $difference_set_arr) . "'");
die;
function spd($minimum_time, $maximum_time)
{
# 日期必须使用字符串类型 因为日期不是数值类型
$collection = [];
// 循环计算
$minimum_time = strtotime($minimum_time);
$maximum_time = strtotime($maximum_time);
while ($minimum_time <= $maximum_time) {
$collection[] += $minimum_time;
$minimum_time = strtotime('+1 day', $minimum_time);
}
foreach ($collection as &$value) {
$value = date('Y-m-d', $value);
}
return $collection;
}
边栏推荐
猜你喜欢
随机推荐
二叉树详解
学编程的第七天
网络——IPV4地址(二)
4. Using Local Geospatial Data
我的第一篇博客
小心使用C语言realloc()函数!!!
Access Characteristics of Constructor under Inheritance Relationship
2021深圳杯A题思路 火星探测器着陆控制方案
Foreword: About the author Dr. Wu Qiusheng and an introduction to the book
Chapter 4: Using Local Geospatial Data (4.6-4.14)
Three ways to find prime numbers
学编程的第五天
5. Visualizing Geospatial Data
Two ways to find the factorial of n
网络——路由器
Codeforces Round #808 (Div. 2)||沉淀
网络——IPV4地址(三)
线性表重点之链表
网络——IPV4地址(一)
前言:关于作者吴秋生博士与此书简介