rwahdan1978 Posted 18 hours ago Share Posted 18 hours ago Hi I have a feild in DB that have time() like 2025-04-26 20:30:00. I want to check and get difference between curremt time and the time in DB. example: time in DB is 2025-04-26 20:30:00 current time is 2025-04-26 20:40:00 the time allowed is 15 minutes so from the above example its only passing 10 minutes and have 5 minutes left, how to calculate that? Quote Link to comment https://forums.phpfreaks.com/topic/327533-calculate-time/ Share on other sites More sharing options...
maxxd Posted 18 hours ago Share Posted 18 hours ago Check out https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html#function_datediff Quote Link to comment https://forums.phpfreaks.com/topic/327533-calculate-time/#findComment-1653446 Share on other sites More sharing options...
Barand Posted 12 hours ago Share Posted 12 hours ago The DATEDIFF() function will give the difference in days. Use TIMESTAMPDIFF() which lets you the specify the units for the result. mysql> SELECT NOW(), timestampdiff(SECOND, '2025-04-26 20:30:00', NOW()) as diff; +---------------------+------+ | NOW() | diff | +---------------------+------+ | 2025-04-26 21:34:51 | 3891 | +---------------------+------+ 1 row in set (0.00 sec) mysql> SELECT NOW(), timestampdiff(MINUTE, '2025-04-26 20:30:00', NOW()) as diff; +---------------------+------+ | NOW() | diff | +---------------------+------+ | 2025-04-26 21:35:22 | 65 | +---------------------+------+ 1 row in set (0.00 sec) Quote Link to comment https://forums.phpfreaks.com/topic/327533-calculate-time/#findComment-1653454 Share on other sites More sharing options...
maxxd Posted 10 hours ago Share Posted 10 hours ago Well, crap - I meant to link to the page as a whole, not the anchor tag. Thanks for the correction! Quote Link to comment https://forums.phpfreaks.com/topic/327533-calculate-time/#findComment-1653456 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.