1

I am trying to get few inputs of time periods from users (it can be by choosing in dropdown). let's say a user will be able to input in one field: "1 hour and 5 minutes" or 01:05; In second field the user will be able to input: "2 hours and 25 minutes" or 02:25;

Then, I want to calculate and add up the two time peirods for: "3 hours and 30 minutes" or 03:30;

It's important that all the date and time fields will be saved in ISO 8601 format, for google.

Someone can help, How can I do that?

Thanks!

  • I saw that Here: support.google.com/webmasters/answer/146645?hl=en "The date that the item was reviewed in ISO date format." SO, what should I do? – EB84 Nov 11 '13 at 9:58
  • Thank you for your very kind comment. I explain that I need to collect time period / time field / I don't know how to else call it / hours and minutes / e.g "1 hour and 5 minutes". Can someone please explain to me (since I am a newbie) what I need to do, in order for google to be able to read my data ? And how can I define a field that will calculate. e.g.: ("1 hour and 5 minutes" or 01:05) + ("2 hours and 25 minutes" or 02:25) = ("3 hours and 30 minutes" or 03:30)? – EB84 Nov 11 '13 at 12:00
2

You're asking two completely unrelated questions here. To rephrase:

  1. How can I provide Google with dates in a format that Google's scraper will recognize, as specified in Rich snippets - Reviews?

  2. How can I accumulate time periods and present the result in a format suitable for humans?

Asking two unrelated question in one question is depreciated on SE, and will usually get your question closed, but I am going to answer them anyway.

First question: The ISO 8601 format requested by Google is YYYY-MM-DD with leading zeros if required, so July the 4th 2013 would be 2013-07-04.

To format the ISO date you can use the PHP function date like this:

$isodate = date('Y-m-d', $timestamp);

where $timestamp is an integer with the number of seconds that has elapsed since the Unix Epoch (January 1 1970 00:00:00 GMT).

Further, Google expects the $isodate string to be embedded in the page attached to the dtreviewed property using the syntax one of three metadata schemes (microdata, microformats, or RFDa). You do this in Drupal by overriding the template of page, node, etc. you want to embed the dtreviewed property in.

Second question: To accumulate time periods, you need to convert periods input by users (such as "1 hour and 5 minutes" or "01:05") to an integer format with seconds resolution. To convert to seconds you multiply the days with 86400, the hours with 3600 and the minutes with 60, so "1 hour and 5 minutes" becomes:

1 (hour) * 3600 + 5 (minutes) * 60 + 0 (seconds) = 3900 (seconds)

and "2 hours and 25 minutes" becomes:

2 (hour) * 3600 + 25 (minutes) * 60 + 0 (seconds) = 8700 (seconds)

To accumulate, you just add the seconds:

3900 + 8700 = 12600 (seconds)

To display in a suitable format, you can use format_interval.

$interval = 3900 + 8700;
$intervalstring = format_interval($interval, 2);

and $intervalstring will now be:

3 hours 30 minutes

(You will lose the "and" by using this standard function, if this "and" is important, you'll need to write your own.)

For avoidance of misunderstanding: Goggle is not interested in your time period data. A time period is typically an interval made up of hours and minutes, and not attached to a particular date. Google wants dates (as in year, month and day of month). Dates and time periods are different things, and there is no way you can format a time period as a date, or vice versa.

  • first of all, Many thanks for your great explanation! second, it was unclear for me before I asked. I need two formats: 1.The date that the item was reviewed in ISO date format. link: support.google.com/webmasters/answer/146645?hl=en 2.The total time it takes to prepare the cook the dish, in ISO 8601 duration format. Can use min, max as child elements to specify a range of time. link: support.google.com/webmasters/answer/…. So I really needs both. for this I will need "interval made up of hours and minutes"? Can I get the duration the same way? – EB84 Nov 11 '13 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.