Possible Duplicate:
Timestamps of start and end of month
I want to find the Start and end Date of the previous month in php (ie) i want to find the last month start and end date of the current month
You can be creative with this. For example, to get the first and last second of a month: $timestamp = strtotime('February 2012'); $first_second = date('m-01-Y 00:00:00', $timestamp); $last_second = date('m-t-Y 12:59:59', $timestamp); // A leap year!
php $currentMonth = date('n'); $currentYear = date('Y'); if($currentMonth == 1) { $lastMonth = 12; $lastYear = $currentYear - 1; } else { $lastMonth = $currentMonth -1; $lastYear = $currentYear; } if($lastMonth < 10) { $lastMonth = '0' .
In this approach, we can make use of different methods to find out the first and last date of the month. The getDate() method is used for the specified date, that returns the day of the month (from 1 to 31). This method returns the day of the month which is represented by a number between 1 and 31.
php $time1=strtotime($startDate); $time2=strtotime($endDate); $daycount=floor(($time2-$time1)/ 86400); ?> Save this answer.
I guess this would do
echo date('Y-m-d', strtotime('first day of last month'));
echo "<br/>";
echo date('Y-m-d', strtotime('last day of last month'));
echo date('m-01',strtotime('last month')) . '<br/>';
echo date('m-t',strtotime('last month')) . '<br/>';
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