php - 试图找到给定任何日期的前六天

标签 php date strtotime

我正在使用 strtotime 在我的数据库中查找前一周和下周的条目,但我似乎无法找到的是如果用户选择过去的日期,如何找到前六天。

以下是我如何知道今天和六天前的情况:

$today = date("Y-m-d");
$minus6 = date('Y-m-d', strtotime('-6 days'));

现在如何根据用户的输入将 $today 与 $dateString 切换? 我根据我的谷歌搜索想到了这样的事情,但它没有产生任何结果:

$dateString = 2010-01-25; // for example
$minus6 = date('Y-m-d', strtotime('-6 days, $dateString');

我是否遗漏了一些有关日期、strtotime 或其他内容的基本信息?感谢您的帮助。

最佳答案

strtotime 的第二个参数是计算第一个参数的时间戳:

echo date('Y-m-d', strtotime('-6 days', strtotime($dateString));

但你也可以做到like Gavin suggested .

关于php - 试图找到给定任何日期的前六天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2519316/

相关文章:

php - Laravel Eloquent 序列化

java - 如何从日历java中获取接下来7天的日期

php - 为什么 strtotime ('x' ) 返回明天的日期

javascript - 在javascript中比较日期对象的时间部分的最佳方法是什么

java - 如何获得 Joda DateTime 时区的冒号?

php - 无法将日期字符串列表转换为时间戳并获取平均值

php - strtotime php mysql

php - 为什么这种使用数组引用调用 PHP 函数的较短方法会导致不同的结果?

php - 错误:调用未定义的方法 ComposerAutoloaderInit13c2409cfa32d1fa0c04493c0d85c93c::getLoader()

php - 如何将数据从表单插入数据库?