Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

332
Views
Converting a Time from a database to BST with PHP

So I've trying all sorts of combinations to get a date from my database (using Wordpress) to display in British Summer Time and I cannot get anything to work.

Is there any simple solution that can take the date string and make sure that in Summer Time in the UK it's an hour on from UTC time?

$classJson = $class->info;
$classJsonAsArray = json_decode($classJson, TRUE);

$classStartDate = strtotime($class->periodStart);
$classStartTime = date('H:i',$classStartDate);

So currently $class->periodStart returns: 2022-04-06 08:30:00

The time of that event should be 9.30am

All I need it to do is display the correct time, as at the moment, on the front end it displays as 8.30am.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

DateTime handles timezones quite well.

$dateStringInUtc = '2022-04-06 08:30:00';
$date = new DateTime($dateStringInUtc, new DateTimeZone('UTC'));
$date->setTimezone(new DateTimeZone('Europe/London'));

echo $date->format('Y-m-d H:i:s'); // will output 2022-04-06 09:30:00
over 4 years ago · Santiago Trujillo Report

0

Working with DateTime and timezones like in the accepted answer is the better way.

But it also works with strtotime if the timezone is appended to the date string. Date then returns the local time for a timestamp.

$utcDate = '2022-04-06 08:30:00';
echo date('Y-m-d H:i:s',strtotime($utcDate.' UTC'));
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!