How to insert time together with date in c# with Mysql sgbd -

Asked

Viewed 25 times

0

I use this line to save the date when I upload some record to my comic

 sql = "INSERT INTO ativacao (codigo, nomepc, data) VALUES (@codigo, @nomepc, curDate())";

this is only the first line and works very well, I can save the date of inclusion of that record, but I would like to enter together the time, la in my database already changed the field to DATETIME, but what would be the function that saves the time together?

1 answer

0


As you are writing the query, the language of your application is indifferent. Whereas your column data is in the correct format you can use the functions UTC_TIMESTAMP() or NOW(), depending on whether you want to use session time zone or UTC. I recommend always using UTC.

Ex: INSERT INTO ativacao (codigo, nomepc, data) VALUES (@codigo, @nomepc, UTC_TIMESTAMP())

For more details on these functions and other alternatives, please refer to the Mysql documentation: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.