D
D
Dmitry2016-03-09 18:40:14
PHP
Dmitry, 2016-03-09 18:40:14

List of dates from current day?

Hello!
There is a date 2016-02-03, you need to get a list of all dates before the current one, namely until 2016-03-09.
How to implement this in php?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-03-09
@muldy

Can be done with DateInterval

$begin = new DateTime('2016-02-03'); // Начальная дата
$end   = new DateTime('2016-03-09'); // Конечная дата

$interval = DateInterval::createFromDateString( '1 day' );
$period   = new DatePeriod( $begin, $interval, $end );

Then you can get
foreach ( $period as $dt ) {
    echo $dt->format( "Y-m-d" ); //$dt - Datetime
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question