How do I insert the current date to my database? I have a column called date to put it on. I want to insert it at the same time I insert this:
$sql="INSERT INTO `Lines` (Text, PID, Position)
VALUES
('$text','$pid','$position')";
Is there a way to automate it in PHPMyAdmin or it's the same to do it this way? Thanks
If the table definition has the timestamp
column default set to CURRENT_TIMESTAMP
, you actually don't have to do anything at all. Otherwise, NOW()
and CURRENT_TIMESTAMP
will work, as in:
INSERT INTO t1 (timestamp_column) VALUES (NOW());
There is a difference between CURRENT_TIMESTAMP
and NOW()
but it's probably too small to matter to you.
phpMyAdmin seems like it has CURRENT_TIMESTAMP
as an option when creating a new column.
INSERT INTO `Lines` (`date`) VALUES (NOW());
Depending on your requirement, you can also do this
$date=date('d.m.y h:i:s');
And then insert $date. I mean if you only want to view the date & time. Otherwise i also recommend time().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With