shoguniphicus
shoguniphicus

I usually leave the timezone as 'UTC' as it served most of my projects well. But for one particular project, timezone is important because it's being used to show schedule showtime of a channel.

I set mine to "Asia/Kuala_Lumpur", and the recorded saved in MySQL is always +8 hours of the timestamp that I intend to save. The backend fields seems to intelligently corrected the timestamp saved in MySQL to display correctly. For example, if my time now is 12pm, the data saved in MySQL would be 8pm, but the field would still show 12pm. Which is fine by me. I think that's the way the system is designed to work.

What didnt work for me, however, is when I tried to query the record, say if I wanted to get record between certain hours using Carbon:now(), then this would mess me up because Carbon also have take into account of the current timezone and gives me my exact hours of my timezone. So what I do now is that I manually add +8 hours to my query and that gives me the result that I want.

I want to ask if what I am doing is right? because this feels counter-intuitive at best.

brianwachira758369
brianwachira758369

shoguniphicus said:

I usually leave the timezone as 'UTC' as it served most of my projects well. But for one particular project, timezone is important because it's being used to show schedule showtime of a channel.

I set mine to "Asia/Kuala_Lumpur", and the recorded saved in MySQL is always +8 hours of the timestamp that I intend to save. The backend fields seems to intelligently corrected the timestamp saved in MySQL to display correctly. For example, if my time now is 12pm, the data saved in MySQL would be 8pm, but the field would still show 12pm. Which is fine by me. I think that's the way the system is designed to work.

What didnt work for me, however, is when I tried to query the record, say if I wanted to get record between certain hours using Carbon:now(), then this would mess me up because Carbon also have take into account of the current timezone and gives me my exact hours of my timezone. So what I do now is that I manually add +8 hours to my query and that gives me the result that I want.

I want to ask if what I am doing is right? because this feels counter-intuitive at best.

Have you found a solution? So I am also experiencing the same issue when using rainlab blog plugin to save my blog posts. The articles get saved but they are not being displayed till after 3 hours of the publishing time. I changed the timezone in config/app.php to my city. Posts published before 12 noon get displayed but any post published after 12 noon is not shown

Last updated

mjauvin
mjauvin

leave timezone in config/app.php set to UTC and change the one in config/cms.php

1-3 of 3