-4

I've made a DateTime object using

$currtime = DateTime::createFromFormat("YmdHi");

Is there a way to get a string or an integer, which contains, for example, 201604041825?

$currtime->modify("+2 hours");
$newtime = $currtime->format("YmdHi");

returned

$newtime = 2147483647
12
  • 6
    Investigate DateTime::format(). Commented Apr 4, 2016 at 16:28
  • 3
    possible duplicate : stackoverflow.com/questions/10569053/… Commented Apr 4, 2016 at 16:29
  • I've now used the current time. After that, I did $datetime->modify("+2 hours"); and then $datetime->format("YmdHi") returned 2147483647 Commented Apr 4, 2016 at 16:34
  • @BjörnSchönrock Yes, I've deleted comment. I misunderstood your question. See duplicate link for answer. You can use ->format('YmdHi') Commented Apr 4, 2016 at 16:36
  • 1
    Your example is wrong: DateTime::createFromFormat fails without second parameter. Show you second parameter, the problem is in it. Commented Apr 4, 2016 at 16:40

1 Answer 1

1

This will help you

$current_date_object= new DateTime();
$current_date_object->modify("+2 hours");
$current_date_string= $current_date_object->format("Y-m-d H:i:sO");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.