Skip to main content
original example failed in real world
Source Link

If you have a Google Places place_id and API key, the following URL will return the hours as a JSON object.

Just be sure to replace "YOUR_PLACE_ID" with your actual Google Places place_id and "YOUR_API_KEY" with your Google Places API key.

https://maps.googleapis.com/maps/api/place/details/json?placeid=YOUR_PLACE_ID&fields=opening_hours&key=YOUR_API_KEY

You will get hours for each day as both day-of-week-number, from 0 to 6, where Sunday = 0, as well as a standard language array. The numbered days are found in result.opening_hours.periods and the standard language array is result.opening_hours.weekday_text

weekday_text is simpler to use while periods will enable you to do things like display the results in different languages.

You can use any server side language you want to parse the response. If you wanted to use an AJAX requestHere is how it might look something like thisin PHP:

var url$url = 'https://maps.googleapis.com/maps/api/place/details/json?placeid=YOUR_PLACE_ID&fields=opening_hours&key=YOUR_API_KEY';
var xhr
$hours_raw = new XMLHttpRequest@file_get_contents($url);
xhr.onload =if function(!empty($hours_raw)
 ) {
  if$hours_json (xhr.status= ==json_decode($hours_raw, 200true) {;
    var response =if JSON.parse(xhr.responseText!empty($hours_json['result']['opening_hours']);
) {
   var businessHoursArray$business_hours = response.result.opening_hours.weekday_text;$hours_json['result']['opening_hours']['weekday_text'];
    }
}

// Use$business_hours theis an array you can use however you like
  }e.g.
}echo '<ul>';
xhr.openforeach ('GET',$business_hours url,as true$weekday); {
xhr  echo '<li>' .send(); $weekday . '</li>';
}
echo '</ul>';

If you have a Google Places place_id and API key, the following URL will return the hours as a JSON object.

Just be sure to replace "YOUR_PLACE_ID" with your actual Google Places place_id and "YOUR_API_KEY" with your Google Places API key.

https://maps.googleapis.com/maps/api/place/details/json?placeid=YOUR_PLACE_ID&fields=opening_hours&key=YOUR_API_KEY

You will get hours for each day as both day-of-week-number, from 0 to 6, where Sunday = 0, as well as a standard language array. The numbered days are found in result.opening_hours.periods and the standard language array is result.opening_hours.weekday_text

weekday_text is simpler to use while periods will enable you to do things like display the results in different languages.

You can use any server side language you want to parse the response. If you wanted to use an AJAX request it might look something like this:

var url = 'https://maps.googleapis.com/maps/api/place/details/json?placeid=YOUR_PLACE_ID&fields=opening_hours&key=YOUR_API_KEY';
var xhr = new XMLHttpRequest();
xhr.onload = function()
 {
  if (xhr.status == 200) {
    var response = JSON.parse(xhr.responseText);
    var businessHoursArray = response.result.opening_hours.weekday_text;
    // Use the array however you like
  }
}
xhr.open('GET', url, true);
xhr.send();

If you have a Google Places place_id and API key, the following URL will return the hours as a JSON object.

Just be sure to replace "YOUR_PLACE_ID" with your actual Google Places place_id and "YOUR_API_KEY" with your Google Places API key.

https://maps.googleapis.com/maps/api/place/details/json?placeid=YOUR_PLACE_ID&fields=opening_hours&key=YOUR_API_KEY

You will get hours for each day as both day-of-week-number, from 0 to 6, where Sunday = 0, as well as a standard language array. The numbered days are found in result.opening_hours.periods and the standard language array is result.opening_hours.weekday_text

weekday_text is simpler to use while periods will enable you to do things like display the results in different languages.

Here is how it might look in PHP:

$url = 'https://maps.googleapis.com/maps/api/place/details/json?placeid=YOUR_PLACE_ID&fields=opening_hours&key=YOUR_API_KEY';

$hours_raw = @file_get_contents($url);
if (!empty($hours_raw)) {
  $hours_json = json_decode($hours_raw, true);
  if (!empty($hours_json['result']['opening_hours'])) {
    $business_hours = $hours_json['result']['opening_hours']['weekday_text'];
  }
}

// $business_hours is an array you can use however you like e.g.
echo '<ul>';
foreach ($business_hours as $weekday) {
  echo '<li>' . $weekday . '</li>';
}
echo '</ul>';
Source Link

If you have a Google Places place_id and API key, the following URL will return the hours as a JSON object.

Just be sure to replace "YOUR_PLACE_ID" with your actual Google Places place_id and "YOUR_API_KEY" with your Google Places API key.

https://maps.googleapis.com/maps/api/place/details/json?placeid=YOUR_PLACE_ID&fields=opening_hours&key=YOUR_API_KEY

You will get hours for each day as both day-of-week-number, from 0 to 6, where Sunday = 0, as well as a standard language array. The numbered days are found in result.opening_hours.periods and the standard language array is result.opening_hours.weekday_text

weekday_text is simpler to use while periods will enable you to do things like display the results in different languages.

You can use any server side language you want to parse the response. If you wanted to use an AJAX request it might look something like this:

var url = 'https://maps.googleapis.com/maps/api/place/details/json?placeid=YOUR_PLACE_ID&fields=opening_hours&key=YOUR_API_KEY';
var xhr = new XMLHttpRequest();
xhr.onload = function()
{
  if (xhr.status == 200) {
    var response = JSON.parse(xhr.responseText);
    var businessHoursArray = response.result.opening_hours.weekday_text;
    // Use the array however you like
  }
}
xhr.open('GET', url, true);
xhr.send();