so you have a reading every thirty minutes?
If you want two-hour readings, how will you consolidate the four readings into one?
How come you only need day and month, not year? You cannot have a date that has no year -thats just a string
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am working with a weather api just like Dark Sky that saves hourly and daily weather data into my database and i am trying to format the date and time.
I have this in my code
$weather_plot = [];
foreach ($weather_data as $day => $day_data) {
if ($day_data) {
foreach ($day_data as $hour => $data) {
if ($data) {
// Calculate day and hour
$formatted_day = date('d/m', strtotime($data->date));
$formatted_hour = str_pad($hour % 24, 2, '0', STR_PAD_LEFT);
// var_dump($data->date);
// Construct timestamp
$timestamp = strtotime($data->date . ' +' . $hour . ' hours') * 1000;
$weather_plot[] = [$timestamp, $data->temperature];
if ($min_temp === null || $max_temp === null) {
$min_temp = $max_temp = $data->temperature;
} else {
$min_temp = min($min_temp, $data->temperature);
$max_temp = max($max_temp, $data->temperature);
}
}
}
}
}
When i var_dump($data); i get this example data
public 'building_id' => int 124
public 'date' => string '2023-05-23' (length=10)
public 'hour_of_day' => int 0
public 'summary' => string 'Cloudy' (length=6)
public 'icon' => string 'cloudy' (length=6)
public 'precipIntensity' => float 0
public 'precipProbability' => float 0
public 'temperature' => float 8.74
public 'apparentTemperature' => float 7.35
public 'dewPoint' => float 7.37
public 'humidity' => float 0.91
public 'windSpeed' => float 2.45
public 'windBearing' => float 0.82
public 'visibility' => float 16.09
public 'cloudCover' => float 1
public 'pressure' => float 1007.93
public 'ozone' => float 354.72
and the hour_of_day goes from 0 to 47. Also the date is 2023-05-23 which is usually the previous date from current date.
My Question now is that how do i format the date to me d/m for each hour and also get the time in 2hrs interval like 00:00, 02:00, 04:00, 06:00, 08:00, 10:00, 12:00, 14:00, 16:00, 18:00, 20:00 and 22:00
Please or to participate in this conversation.