-1

I need to retrieve the 15th day of the next month with using a single strtotime call only with a single literal string argument.

I tried the following argument values:

  • strtotime("15th of next month")
  • strtotime("first day of next month + 14 day")
  • strtotime("15 day of next month")

But nothing gives me expected result. Is this doable at all?

UPD. The solutions which make calls to other functions inside strtotime() are not what I'm looking for. The issue is that I need the string function to be non-composed as a result of other calculations, but rather a string literal. That's the main way my question is different to the others that may look similar at first glance.

Meglio
  • 1,646
  • 2
  • 17
  • 33
  • What you tried are bullets, not code. Hard to help here. – Funk Forty Niner Aug 04 '16 at 13:42
  • 2
    I think this question has been asked before [once](http://stackoverflow.com/questions/33603709/how-to-get-every-15th-and-last-day-of-the-month-in-php) [twice](http://stackoverflow.com/questions/33525932/get-the-date-of-the-next-15th-and-or-30th-day-with-php) – RiggsFolly Aug 04 '16 at 13:46
  • What, no thrice? @RiggsFolly – Funk Forty Niner Aug 04 '16 at 13:49
  • The items in the list are string values passed to `strtotime`. I can't see the question being duplicated elsewhere, and none of the answers given below actually answer my question. – Meglio Aug 10 '16 at 13:52
  • @aynber I explained how it is not duplicate of the other question. I wonder why is my question is still marked Duplicate while it is not. The answers in the other question are not applicable. – Meglio Dec 08 '16 at 23:40

2 Answers2

0

Edited

<?php echo strtotime(date('Y', strtotime('+1 month')).'-'.date('m', strtotime('+1 month')).'-15'); ?>
simialbi
  • 507
  • 3
  • 10
  • What happens in February? – RiggsFolly Aug 04 '16 at 13:47
  • February might be fine. December, on the other hand... – aynber Aug 04 '16 at 13:48
  • @RiggsFolly It freezes everything, including what's in your knickers. – Funk Forty Niner Aug 04 '16 at 13:50
  • Now it should work :-) – simialbi Aug 04 '16 at 13:51
  • Seems to work ignoring the 2038 bug – RiggsFolly Aug 04 '16 at 14:02
  • While this code snippet may solve the question, [including an explanation](//meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, as this reduces the readability of both the code and the explanations! – Blue Aug 04 '16 at 19:39
  • This answer does not solve the problem. The question is how to do it "with using a single strtotime call only with a single string argument". By this I mean a non-compasable string argument. – Meglio Aug 10 '16 at 13:56
-1

Try this code

$d = strtotime("next Month +15 day"); 
echo date("Y-m-d",$d);