Re: Adding a relative amount of time to an absolute time.
| From: | Marc Guay | Date: | Tue, 07 Apr 2015 12:42:44 +0000 |
| Subject: | Re: Adding a relative amount of time to an absolute time. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-324772@lists.php.net to get a copy of this message | ||
Hi Richard,
I looked around a bit and it does seem clunky to convert a HH:MM:SS
string to a DateInterval object. Why not store the buffer time as
seconds only, and then do something like
$date = new DateTime($event_datetime);
$date->add(new DateInterval('P'.$buffer_time.'S'));
echo $date->format('Y-m-d') . "\n";
Marc
On 7 April 2015 at 07:45, Richard Quadling <rquadling@gmail.com> wrote:
> Hi.
>
> This sort of stuff always makes me wonder what it is I am missing.
>
> The users are asked to enter a buffer time in the format HH:MM
>
> This time will be added to the end of an event datetime to determine what
> the next available event will be for that user.
>
> The entered value is stored in the DB as a time type (so is returned as a
> string "HH:MM:SS").
>
> Can I use anything in DateTime to handle this (I was thinking of
> DateTimeInterval but that doesn't want to deal with a simple time only
> string).
>
> My other option is to parse out the string into H, M and S and then
> construct that as a strtotime sort of thing.
>
> In general, this sort of parsing always suggests I've missed a
> trick/function/method.
>
> So, is there something I'm missing?
>
> Regards,
>
> Richard.
>
>
>
> --
> Richard Quadling
> Twitter : @RQuadling
> EE : http://e-e.com/M_248814.html
> Zend : http://bit.ly/9O8vFY