Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql NOW() + $seconds php?

Tags:

php

mysql

Is it possible to use mysqls NOW() function and add seconds to or from it?

Like so;

$q = $dbc -> prepare ("UPDATE account SET time = NOW() + $seconds WHERE id = ?");

Thanks

like image 505
cgwebprojects Avatar asked Dec 05 '22 18:12

cgwebprojects


2 Answers

If you want to do this in MySql, you can either use

DATE_ADD(NOW(), INTERVAL $seconds SECOND)

or

UNIX_TIMESTAMP() + $seconds

Source

  • unix_timestamp()
  • date_add()
  • INTERVAL $seconds
like image 189
Jon Avatar answered Dec 10 '22 09:12

Jon


You can add seconds to it with DATE_ADD():

$q = $dbc -> prepare ("UPDATE account SET time = DATE_ADD(NOW(), INTERVAL $seconds SECONDS) WHERE id = ?");
like image 42
Michael Berkowski Avatar answered Dec 10 '22 11:12

Michael Berkowski