| | |
how to get previous month starting and ending date in php
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2009
Posts: 254
Reputation:
Solved Threads: 37
i am giving an idea
apply if condition that if current month is greater than one and less and equal to 12 then
offcource the first date will be 1st and you can take end date as
PHP Syntax (Toggle Plain Text)
$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
PHP Syntax (Toggle Plain Text)
$lastmonth=$current_month-1;
offcource the first date will be 1st and you can take end date as
PHP Syntax (Toggle Plain Text)
$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 ;
Last edited by BzzBee; Apr 28th, 2009 at 8:24 am.
what to confused..
you can write..
you can write..
PHP Syntax (Toggle Plain Text)
if($current_month==1) { $lastmonth=12; } else { $lastmonth=$current_month-1; }
Last edited by Shanti Chepuru; Apr 29th, 2009 at 1:40 am.
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
•
•
Join Date: Apr 2009
Posts: 254
Reputation:
Solved Threads: 37
or one more simple solution to get last month
$lastmonth = mktime(0, 0, 0, date("m")-1, date("d"), date("Y"));
$lastmonth = mktime(0, 0, 0, date("m")-1, date("d"), date("Y"));
•
•
Join Date: Apr 2009
Posts: 254
Reputation:
Solved Threads: 37
or one more simple solution to get last month
PHP Syntax (Toggle Plain Text)
$lastmonth = mktime(0, 0, 0, date("m")-1, date("d"), date("Y"));
•
•
•
•
what to confused..
you can write..
PHP Syntax (Toggle Plain Text)
if($current_month==1) { $lastmonth=12; } else { $lastmonth=$current_month-1; }
thnx maan..!!! i did the same thng..!!
.
.
Query Sloved..!!
.
.
CHeers..!!
•
•
•
•
i am giving an idea
PHP Syntax (Toggle Plain Text)
$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
PHP Syntax (Toggle Plain Text)
$lastmonth=$current_month-1;
offcource the first date will be 1st and you can take end date as
PHP Syntax (Toggle Plain Text)
$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 ;
this line still show the current month days not last month..!!
any other solution to get last month number of days...!!
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.
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.
PHP Syntax (Toggle Plain Text)
$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; }
Last edited by Shanti Chepuru; May 8th, 2009 at 6:43 am.
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
![]() |
Other Threads in the PHP Forum
- Previous Thread: How to avoid the following error while sending newsletter
- Next Thread: Using cookies for user login .....
| Thread Tools | Search this Thread |
# 5.2.10 alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions simple sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube






