Good day. How to add a date through PHP to MySQL ?.

I read dozens of articles in Google and on this site, but nothing helped.

If I write date('Ym-d'); - date adds.

If I write date('Ymd H:i:s'); - neither the date nor the time does not add.

Everyone writes that with date('Ymd H:i:s') everything works for everyone, but I don’t, I don’t understand why.

Yes, I could create a table in the database ( CURRENT_TIMESTAMP ) and would not be steamed, but this does not suit me, because after sending the date I’m checking for a duplicate on duplicate key update , if I already have such a record, I just need to update the date and all

Thanks in advance to everyone for their help.

  • one
    insert into table(...) values(...,now()) on duplicate key update set dt=now() - Mike

1 answer 1

Try changing the field type in the table from date to datetime .

  • Then timestamp, columns with this type are automatically updated to the current date during any operation insert / update - Mike
  • I can change to timestamp and then I don’t have to do an INSERT with a date, but how can I do on duplicate key update in this case? - Vladimir V.
  • one
    @ VladimirV. And in update, any field itself does not change everything, but it will change the date itself. but you can also change nothing and write a request as I suggested to you in the comments to the question. MySQL's now () function gives current date-time - Mike