我想根据开始日期和结束日期获得每周日期。
假设我的开始日期是'2015-09-08',结束日期是'2015-10-08'。
基于这些日期,我希望使用PHP得到以下结果。我希望每周的日期介于开始日期和结束日期之间。
2015-09-15
2015-09-22
2015-09-29
2015-10-06
您可以获取开始日期和结束日期的时间戳,并在当前日期上添加一周的时间戳直到它小于结束日期时间戳。
下面这样的东西。检查这是否是你要求的
$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>';
}
尝试使用:
select *
from table_name
where Column_name > '2015-09-08'
and Column_name < '2009-10-08'
或
SELECT *
FROM Table_name
WHERE Column_name BETWEEN ‘2015-09-08’ AND ‘2015-10-08’
如果您想要使用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的strtotime函数在这里可能很方便。你可以试试这个:
$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') ;
}
这里的链接有代码可以做你想做的事情,你可以得到每个星期日或星期一的日期,或者你在两个日期之间选择的任何一天
试试这个:
<?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)));
}
?>