Time difference problems when using FROM_UNIXTIME() – localhost vs. server – php / MySQL

I am trying to create an appointment booking system for a hairdresser.

The conception is that they open at 9:00 and close at 15:30. This is my timeframe.

Steps of booking:

  • choosing the service (it contains the duration of the service is seconds)
  • choosing the desired date (will be passed to a function when checking dates)
  • select date

I loop through the day and use the duration of the service to create timeslots, comparing if it the calendar has enough time to book before next scheduled appointment.

My problem is that now that we want to go live, timestamps for the bookable slots are different.

Let’s say I want to book for 2022-12-15 09:00:00.

On my local machine the timestamp is 1671091200.

And on the server for same card I get a value of 1671094800.

The problem is coming from here I guess:

$Date = "2022-12-15"; //this is a date coming from a dropdown
$DayStart = strtotime($Date." 09:00:00");

After converting to time, I have the time mentioned above: 1671091200

I discovered, that there are due to different time zone settings and most probably my machine is using UTC and the server CET.

I am based in Hungary and the website will go live in Germany and somehow I have to make sure that if I book for 09:00:00, it won’t be registered as 10:00:00.

And of course for future developments I need to know how to avoid this.

One more important thing. I am using the same remote database from the server. I open localhost, connect to db on server and works good – then open domain, connect to exact same db on same server and everything is shifted +1 hour,

Maybe if there is another option to maintain this without unix time, I am open to everything but calculations with duration seconds are done this way.

Currently I am using this query but I may have to prepare time data in php instead of MySQL:

INSERT INTO `timetable.appointments` (Name, Phone, Email, AppDate, AppStart, AppEnd, Duration, ServiceID) VALUES (?,?,?,?,from_unixtime(?),from_unixtime(?),?,?)

Thanks for reading and thinking along!

Have a nice day!

I tried to open the site from different hosts (localhost / domain) but I am not able to find an answer how to fix that in the future.