Jump to content

Recommended Posts

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? 

Link to comment
https://forums.phpfreaks.com/topic/327533-calculate-time/
Share on other sites

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)

 

Link to comment
https://forums.phpfreaks.com/topic/327533-calculate-time/#findComment-1653454
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.