Insert current date in a mysql table - php

0

I have a question about inserting the current date in a row into a mysql table in case there is no such record. Example: Insert 2017-10-10 in a row if it does not exist. But insert a new record in case it's another day like tomorrow (2017-10-11). I had read something with curdate () and NOW (), but I'm not sure what would be right or more appropriate.

    
asked by Beta 10.10.2017 в 21:25
source

2 answers

3

Difference between CURDATE () vs NOW ()

CURDATE () returns the current date in format 'YYYY-MM-DD' or YYYYMMDD, depending on whether the function is used as a string (string) or as a number (numeric).

mysql> SELECT CURDATE();
        -> '2008-06-13'
mysql> SELECT CURDATE() + 0;
        -> 20080613

NOW () Returns the current date and time in the format 'YYYY-MM-DD HH: MM: SS' or YYYYMMDDHHMMSS, depends on whether the function is used as a string or as a number.

mysql> SELECT NOW();
        -> '2007-12-15 23:50:26'
mysql> SELECT NOW() + 0;
        -> 20071215235026.000000
    
answered by 11.10.2017 в 01:56
0

You just have to use the NOW() function and insert date and time of the moment.

INSERT INTO tabla (campo1, campo2)
VALUES (NOW(), valor);
    
answered by 10.10.2017 в 22:07