-3

I have a number of month in range 1-12

How to get start and end of date by month number like this:

2018-01-01 - 2018-31-01
Karabah
  • 229
  • 1
  • 4
  • 12
  • 1
    You may want to look at [strtotime](http://php.net/manual/en/function.strtotime.php) and [mktime](http://php.net/manual/en/function.mktime.php). – Alex Barker Mar 23 '18 at 01:19
  • I am not sure, I know current year and number of month, in conclusion I need to get datetime format for insertion to db – Karabah Mar 23 '18 at 01:21
  • use `t` in format. https://stackoverflow.com/questions/1686724/how-to-find-the-last-day-of-the-month-from-date – Joseph D. Mar 23 '18 at 01:22
  • 1
    and start day is always `1` right? unless you're from other planet – Joseph D. Mar 23 '18 at 01:25
  • Read about the [DateFormat](http://php.net/manual/en/datetime.format.php) class. – Alex Barker Mar 23 '18 at 01:25
  • Possible duplicate of [How to find the last day of the month from date?](https://stackoverflow.com/questions/1686724/how-to-find-the-last-day-of-the-month-from-date) – Alex Barker Mar 23 '18 at 01:26
  • Read question carefully. I talk about month, not days – Karabah Mar 23 '18 at 12:49

1 Answers1

-1
$month = '01';
$start_date = date('Y-'.$month.'-01');
$end_date = date('Y-'.$month.'-t');