Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server default date time stamp?

Tags:

sql

sql-server

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?

like image 973
Snow_Mac Avatar asked Aug 09 '11 20:08

Snow_Mac


People also ask

What is default timestamp in SQL?

TIMESTAMP has a default of 0 unless defined with the NULL attribute, in which case the default is NULL .

How do I find the default date in SQL Server?

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.

How do I get the current timestamp in SQL query?

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).


1 Answers

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.

like image 189
JNK Avatar answered Oct 23 '22 03:10

JNK