如果我有两个日期20-4-2010和22-4-2010
在两个文本框和
我想要的日期是这样的20,21,22.我该怎么做?
在两个文本框和
我想要的日期是这样的20,21,22.我该怎么做?
我很确定这已经回答了十几亿次,但无论如何:
- $start = strtotime('20-04-2010 10:00');
- $end = strtotime('22-04-2010 10:00');
- for($current = $start; $current <= $end; $current += 86400) {
- echo date('d-m-Y',$current);
- }
10:00部分是为了防止代码由于夏令时而跳过或重复一天.
通过给出天数:
- for($i = 0; $i <= 2; $i++) {
- echo date('d-m-Y',strtotime("20-04-2010 +$i days"));
- }
用PHP5.3
- $period = new DatePeriod(
- new DateTime('20-04-2010'),DateInterval::createFromDateString('+1 day'),new DateTime('23-04-2010') // or pass in just the no of days: 2
- );
- foreach ( $period as $dt ) {
- echo $dt->format( 'd-m-Y' );
- }