Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the start and end date of a previous month in PHP [duplicate]

Tags:

php

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

like image 652
akila Avatar asked Apr 04 '11 06:04

akila


People also ask

How can I get start date and end of month in php?

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!

How can I get last date of previous month in php?

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' .

How do I find the first and last date of the month?

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.

How can I calculate start date and end date in php?

php $time1=strtotime($startDate); $time2=strtotime($endDate); $daycount=floor(($time2-$time1)/ 86400); ?> Save this answer.


2 Answers

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'));
like image 90
Santosh Linkha Avatar answered Oct 31 '22 12:10

Santosh Linkha


echo date('m-01',strtotime('last month')) . '<br/>';
echo date('m-t',strtotime('last month')) . '<br/>';
like image 42
Lawrence Cherone Avatar answered Oct 31 '22 11:10

Lawrence Cherone