0

I've been trying to create a function that converts something like 3d4h into the current unixtime+the number of seconds within that string. I unfortunately have not been successful, and now I'm turning to you all. Thanks for any help!

John Conde
  • 217,595
  • 99
  • 455
  • 496
benjking1
  • 3
  • 2
  • "converts something like 3d4h into the current unixtime+the number of seconds within that string" relative to when? – John Conde Mar 13 '14 at 23:55
  • You need to be more precise with your question so that that people that can help you, can help you, and so that others who might be in the same situation can easily find a solution to the problem. – Liam J Mar 13 '14 at 23:58
  • John: Relative to the current unixtime (i.e.: 1394766966+3Y14H) I think you actually answered it, I just had to change the format from Y-m-d H:i:s to U. – benjking1 Mar 14 '14 at 03:19

1 Answers1

2

DateTime() and DateInterval() already do this for you:

$interval = new DateInterval('P3DT4H');
$now = new DateTime();
$now->add($interval);
echo $now->format('Y-m-d H:i:s');

This example adds an interval to "now". You can, of course, make the interval relative to any date and time.

See the interval spec for what valid values are for DateInterval().

John Conde
  • 217,595
  • 99
  • 455
  • 496