I want to get date by year in php. (Ex. from 1995 to 2013). can anyone please help me on this?
01-01-1995 02-01-1995 . . . . . 31-01-2013
I want to get date by year in php. (Ex. from 1995 to 2013). can anyone please help me on this?
01-01-1995 02-01-1995 . . . . . 31-01-2013
I think what you're trying to do is get all dates between for example 1995 and 2013. This is called a period. PHP has some nice tools to do this. For example try looking at a DatePeriod. Your code could be like this:
$period = new DatePeriod(
new DateTime('1995-01-01'),
new DateInterval('P1D'),
new DateTime('2013-01-31')
);
This gives you a DatePeriod object that is filled with all dates using Traversable so you can iterate over it using a foreach loop. The interval you need is Per 1 Day (P1D). Next you need to fill your own array with the desired format. Like this for example:
foreach( $period as $date) { $array[] = $date->format('Y-m-d'); }
Or simply print the dates like so:
foreach( $period as $date) { echo $date->format('Y-m-d') . "<br />"; }
I hope this helps. Info found at: PHP: Return all dates between two dates in an array