I tried to make time with PHP. start date of 2017-01-29 to 2017-12-29. But that happened I could not print in February because the month maximum of only 28 days. How to order printed anyway but with the February date up to 28.
my script :
date_default_timezone_set('UTC');
// Start date
$date = '2017-01-29';
// End date
$end_date = '2017-12-29';
while (strtotime($date) <= strtotime($end_date)) {
echo "$date\n";
echo "<br>";
$date = date ("Y-m-d", strtotime("+1 month", strtotime($date)));
}
Output :
To get all of the dates between 2 dates: Copied! function getDatesInRange(startDate, endDate) { const date = new Date(startDate. getTime()); const dates = []; while (date <= endDate) { dates.
We can get the dates between two dates with single method call using the dedicated datesUntil method of a LocalDate class. The datesUntill returns the sequentially ordered Stream of dates starting from the date object whose method is called to the date given as method argument.
The date function in PHP is used to format the timestamp into a human desired format. The timestamp is the number of seconds between the current time and 1st January, 1970 00:00:00 GMT. It is also known as the UNIX timestamp.
use this
date ("Y-m-t", strtotime("+1 month", strtotime($date)));
instead of this to get last day of the month
date ("Y-m-d", strtotime("+1 month", strtotime($date)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With