[英]Query for a list of multiple-day events occurring between today and one week from today based on start date and end date
[英]Get the date of one week from today
如何以以下格式獲取從今天起一周的日期:YYYY-MM-DD?
嘗試:
date("Y-m-d", strtotime("+1 week"));
這將輸出:
2015-12-31
如果今天是 2015-12-24
只是查爾斯的預測是錯誤的,這是一個 PHP 5.3+ 示例:
$now = new DateTime;
$interval = new DateInterval('P1W')
$next_week = $now->add($interval);
echo $next_week->format('Y-m-d');
或者稍微更緊湊的形式:
$now = new DateTime();
echo $now->add(new DateInterval('P1W'))->format('Y-m-d');
將天、周、月添加到任何日期
$date = date("Y-m-d");// current date
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 day");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 week");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +2 week");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +1 month");
$date = strtotime(date("Y-m-d", strtotime($date)) . " +30 days");
<?php
$nextWeek = time() + (7 * 24 * 60 * 60);
echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n";
查爾斯預測中缺少一個,直接來自馬口,示例#1
for ($i=0 ; $i < 7 ;$i++)
{
$date[]=date('Y-m-d',strtotime("+{$i} day",time()));
}
print_r($date);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.