I have a field that when something is inserted I want it to get the current Date & Time and insert this into the database. Is there a way to get the date & time, and set it as the default value?
Currently the default value is: (getdate()) Which sets only the date. How do I also set the time?
TIMESTAMP has a default of 0 unless defined with the NULL attribute, in which case the default is NULL .
SYSDATETIME() will get the current date and time. Make sure the data type of the column is datetime , and not just date or it won't be able to hold a datetime. Show activity on this post. Most SQL implementations (engines) do have CURRENT_TIMESTAMP function.
MySQL CURRENT_TIMESTAMP() Function The CURRENT_TIMESTAMP() function returns the current date and time. Note: The date and time is returned as "YYYY-MM-DD HH-MM-SS" (string) or as YYYYMMDDHHMMSS. uuuuuu (numeric).
GETDATE()
is a date and time in SQL Server.
Run SELECT GETDATE()
to verify this.
What is the datatype of your field? If it's DATE
then it will not hold time values as well.
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