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

Posted on 2010-11-24
Last Modified: 2012-06-21
I want the current month's start, end date using PHP. what is the easiest method to find out?
Question by:Loganathan Natarajan
  • 2
  • 2
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34203798
you can use mktime() to do so:
$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

LVL 17

Expert Comment

ID: 34203848
$start = date('dmY');
$start{0} = '0';
$start{1} = '1';
$endmonth = date('tmY');
LVL 36

Author Comment

by:Loganathan Natarajan
ID: 34203852
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
LVL 142

Accepted Solution

Guy Hengel [angelIII / a3] earned 125 total points
ID: 34203885
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

LVL 36

Author Closing Comment

by:Loganathan Natarajan
ID: 34204133

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Wordpress Query 1 31
Mail Not Sent 6 41
Php Array Diff 3 26
How can I store the VALUE of an object property in a variable? 16 24
Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now