A
A
Andrey2018-06-09 16:37:05
PHP
Andrey, 2018-06-09 16:37:05

How to get the second day of the month?

print_r(new DateTime('first day of -1 month'));
/*DateTime Object
(
    [date] => 2018-05-01 16:35:12.011108
    [timezone_type] => 3
    [timezone] => Etc/GMT-3
)*/


How to get another day in a month, for example the eighth?

update
You need to specify the date in one line, which will be specified in the config. No code additions.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Андрей Буров, 2018-06-09
@BuriK666

php.net/manual/ru/datetime.add.php

<?php
    $date = new DateTime('first day of -1 month');
    $date->Add(new DateInterval("P5D"));
    var_dump($date);

object(DateTime)#1 (3) {
  ["date"]=>
  string(26) "2018-05-06 13:43:58.770116"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(3) "UTC"
}

E
Exploding, 2018-06-09
@Exploding

Не очень четко описана суть задачи: что конкретно имеется и что конкретно нужно получить. А не "например".
Возможно поможет strtotime?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question