I am trying to create a countdown timer. I have created_at
value, life_time
value and current_time
.
I want to sum created_at
and life_time
and subtract current_time
.
created_at : 2017-05-22 04:49:54
life_time : 500 (minutes)
and i can find current time like this. (12/10/2002 13:37:25)
But all variables have different format. How can i
created_at + life_time - current_time = I WANT (dd/mm/yyy hh:mm:ss)
created_at
defined as a datetime and lifetime defined as an integer and minutes in mysql.
答案 0 :(得分:0)
将时间单位添加到mysql使用Date_add函数,如下所示:
SELECT DATE_ADD("2017-12-28", INTERVAL 10 MINUTE);
此链接为此提供了很好的示例
https://www.w3schools.com/sql/func_mysql_date_add.asp
时间也可以为负,这将有助于您创建倒计时