我想根据开始日期和结束日期获取每周日期。如何获取开始日期和结束日期之间的每周日期
假设我的开始日期是'2015-09-08'和结束日期是'2015-10-08'。
基于这些日期,我想使用PHP的以下结果。我想要在开始日期和结束日期之间的每周日期。
2015-09-15
2015-09-22
2015-09-29
2015-10-06
我想根据开始日期和结束日期获取每周日期。如何获取开始日期和结束日期之间的每周日期
假设我的开始日期是'2015-09-08'和结束日期是'2015-10-08'。
基于这些日期,我想使用PHP的以下结果。我想要在开始日期和结束日期之间的每周日期。
2015-09-15
2015-09-22
2015-09-29
2015-10-06
你可以采取两者的时间戳开始日期和结束日期,并不断增加1周的时间戳为当前日期,直到它小于结束日期时间戳。
像下面的东西。检查,如果这是什么ü要求
$st=strtotime("2015-09-08");
$ed=strtotime("2015-10-08");
$wk=$st;
while($wk<$ed){
$wk = strtotime('+1 Week',$wk);
if($wk<$ed)
echo date("Y-m-d",$wk);
echo '<br>';
}
当你想使用PHP每周日期。下面的代码将为你做
<?php
$startdate='2015-09-08';
$enddate='2015-10-08';
$date=$startdate;
while($date<=$enddate)
{
$date = strtotime("+7 day", strtotime($date));
$date=date("Y-m-d", $date);
if($date<=$enddate)
echo $date."<br>";
}
?>
Php s stototime函数可能来这里很方便。你可以试试这个:
$start = '2015-09-08';
$end = // you end date as string
$offset = strtotime($start);
$limit = strtotime($end);
for($t = $offset; $t < $limit; $t += 86400 * 7){
echo date('Y m d') ;
}
此链接here有代码做你想要什么,你可以得到每个星期天或星期一或任何的日期一天,你两个日期
尝试之间的选择这样的:
<?php
date_default_timezone_set('Asia/Kolkata');
$startdate= strtotime("15-09-08");
//$startdate= strtotime("08 September 2015");
$enddate= strtotime("15-10-08");
//$enddate= strtotime("08 October 2015");
$jump_date= $startdate;
if($enddate>$startdate)
while($jump_date< $enddate)
{
$jump_date= strtotime("+1 week", $jump_date);
if($jump_date< $enddate)
echo date('Y-m-d', $jump_date).'<br>';
}
?>
使用内置的PHP函数strtotime
添加一段1周
$ds='2015-09-08';
$df='2015-10-08';
$ts=strtotime($ds);
$tf=strtotime($df);
while($ts <= $tf){
$ts = strtotime('+1 week', $ts);
echo date('Y-m-d', $ts).'<br />';
}
<?php
// Set timezone
//date_default_timezone_set('UTC');
// Start date
$date = '2015-09-08';
// End date
$end_date = '2015-10-08';
while (strtotime($date) <= strtotime($end_date)) {
echo $date."<br/>";
$date = date ("Y-m-d", strtotime("+7 day", strtotime($date)));
}
?>
你能改变你的问题吗?更清楚地给出实际输出与所需输出以及用于实现所得结果的代码是什么 – Blip
@Blip:请再次阅读问题。我已经提到了我需要的输出和数据。再读一遍。 –
你已经说过'startDate','endDate'。但是,您发布的输出是您正在获得的输出还是预期的输出。如果它是你得到的输出,那么期望的输出在哪里。最后**获取输出**所需的代码在哪里? – Blip