how to get previous month starting and ending date in php
Hey frndz i m new member of community..!!
.
.
i jst want to knw is there anyway to get the previous month starting and ending date and which is the previoes month..!!!!
.
.
.
.
hope for positive reply..!!
nish123
Junior Poster in Training
83 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
THnxx brother...!!! but wht to do when current month is 1..?? :O
.
.
.
then previous month become 0..
.
.
.
Anyways thanx for reply..!! tht really helps..!! :)
nish123
Junior Poster in Training
83 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
what to confused..
you can write..
if($current_month==1)
{
$lastmonth=12;
}
else
{
$lastmonth=$current_month-1;
}
Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
what to confused..
you can write..
if($current_month==1)
{
$lastmonth=12;
}
else
{
$lastmonth=$current_month-1;
}
thnx maan..!!! i did the same thng..!!
.
.
Query Sloved..!!
.
.
CHeers..!!
nish123
Junior Poster in Training
83 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
i am giving an idea
$current_month=date('m');
$current_year=date('Y');
apply if condition that if current month is greater than one and less and equal to 12 then
$lastmonth=$current_month-1;
offcource the first date will be 1st and you can take end date as
$firstdate= "01/".$lastmonth."/".$current_year ;
$lastdateofmonth=date('t',$lastmonth);// this function will give you the number of days in given month(that will be last date of the month)
$lastdate=lastdateofmonth."/".$lastmonth."/".$current_year ;
$lastmonth = date('t',$lastmonth);
this line still show the current month days not last month..!!
any other solution to get last month number of days...!!
nish123
Junior Poster in Training
83 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
Nop, The above logic will give you the correct output unless no mistake in your code..
And see this is another logic:
As we know the first day of the month and for the last month , here i calculated number of days of last month, then that number is last day of the month.
$last_month=date('m')-1;
$year=date('Y');
function get_last_day($year, $last_month){
$timestamp = strtotime("$year-$month-01");
$number_of_days = date('t',$timestamp);
return $number_of_days;
}
Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162