You have lost the fidelity of the hours, so you must change the login check to compare the expiry date in the user's timezone.
Alternatively store expiry time and keep the full datetime value so that the account expires mid-way through a UTC day
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
What is the best way to manage user expiry in the web application? I've an application developed in laravel in which I set user expiry date as per the plan duration after the payment is successful. All my dates are stored in UTC timezone. My application timezone is also UTC.
For example, Let's say John has placed an order for 1 month subscription plan on 14th Nov 2019 at 18:30 UTC (+05:30) which is his timezone, the Order created date in database will be 14th Nov 2019 at 13:00 UTC. According to this, application will set expiry date to 14th Dec 2019. I'm only storing date in expiry date field because I want to expire the user service as soon as the beginning of the day i.e 14th Dec 2019 at 00:00:01
I'm displaying all data related to date in user's timezone. John has timezone set to UTC (+5:30) so he will see expiry date to 14th Dec 2019.
Now, let assume that John try to login on 14th Dec 2019 at 02:00 UTC (+05:30) which will be 13th Dec 2019 20:30 UTC. My web application compares everything in UTC so the comparison will be as below:
expiry_date > current_date i.e 14th Dec 2019 UTC > 13th Dec 2019 UTC
In the above case it will allow login because UTC date comparison is evaluates to true. But if from user perspective, if we see, it is wrong because user see the expiry date in his timezone. For example in John's timezone which UTC (+5:30), it is already 14th Dec 2019 which is an expiry date so it should not allow.
I'm not sure, Is this right or wrong. But, I wants to know the best practices to handle expiry date when everything is stored in UTC. I think, I need to compare dates after converting to user's timezone.
Any help on this will be a big help to me.
Thanks
You have lost the fidelity of the hours, so you must change the login check to compare the expiry date in the user's timezone.
Alternatively store expiry time and keep the full datetime value so that the account expires mid-way through a UTC day
Please or to participate in this conversation.