The duration time for a recipe is stored in my database as a string like this: "01:50" I am trying to convert it to the ISO 8601 duration standard with no success.
This is what I use to call the field and parse it the page:
$totalTime = ($extraField->value);
$itempr = "itemprop=\"totalTime\" content=\"$totalTime\"";
Like this, it appears in the Google structured data testing tool as "00:50" which is not accepted by Google. From what I understand, it should appear like this: PT1H50M
Has anyone got any ideas on how to convert it to the ISO 8601 format? Please, keep in mind that I am not to keen on development with PHP so be as explanatory as possible. Thanks!
Like you already wrote in the comments :
echo (new DateTime('01:50'))->format('\P\TG\Hi\M');
or you can convert it already in the database using TIME_FORMAT function :
SELECT TIME_FORMAT('01:50', 'PT%kH%iM');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With