[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1057
  • Last Modified:

How to get current month starting and ending date in php?

I want the current month's start, end date using PHP. what is the easiest method to find out?
0
Loganathan Natarajan
Asked:
Loganathan Natarajan
  • 2
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you can use mktime() to do so:
http://www.php.net/manual/en/function.mktime.php
http://php.net/manual/en/function.date.php
$month = date("n");
$year = date("Y");
$this_month_start = mktime(0,0,0, $month, 1, $year);
$next_month_start = mktime(0,0,0, $month + 1, 1, $year);

Open in new window


note, you will use some condition like:
yourvalue >= $this_month_start AND yourvalue < $next_month_start

hope this helps

0
 
sweetfa2Commented:
$start = date('dmY');
$start{0} = '0';
$start{1} = '1';
$endmonth = date('tmY');
0
 
Loganathan NatarajanLAMP DeveloperAuthor Commented:
how can i format this as YYYY-mm-dd

actually i need to take  month starting and end date to get the 1 month results dynamically..

for example this month,

starting date = 2010-11-01
end date = 2010-11-30
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you use date() function again:

$month = date("n");
$year = date("Y");
$this_month_start = mktime(0,0,0, $month, 1, $year);
$next_month_start = mktime(0,0,0, $month + 1, 1, $year);
print date("Y-n-d", $this_month_start);
print date("Y-n-d", $next_month_start);

Open in new window

0
 
Loganathan NatarajanLAMP DeveloperAuthor Commented:
thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now