adding 30 minutes to datetime php/mysql

Viewed 122152

I have a datetime field (endTime) in mysql. I use gmdate() to populate this endTime field.

The value stored is something like 2009-09-17 04:10:48. I want to add 30 minutes to this endtime and compare it with current time. ie) the user is allowed to do a certain task only 30 minutes within his endTime. After 30 minutes of his endTime, i should not allow him to do a task.

how can i do that in php?

i'm using gmdate to make sure there are no zone differences.

Thanks in advance

6 Answers

Get date from MySQL table by adding 30 mins

SELECT loginDate, date_add(loginDate,interval 30 minute) as newLoginDate 
FROM `tableName`;

This will result like below

Login Date - 2020-07-22 14:00:00
New Login Date - 2020-07-22 14:30:00
Related