Click here to Skip to main content
15,889,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi,

how to insert current time in sql server database ??
Posted
Comments
PIEBALDconsult 28-Feb-14 15:54pm    
UTC? Local? Local with offset?

SQL
INSERT INTO table_name(date_field_name)
VALUES (CONVERT(time, GETDATE()))


If you want the date and time, simply use GETDATE() alone:

SQL
INSERT INTO table_name(date_field_name)
VALUES (GETDATE())
 
Share this answer
 
Comments
Manish Dalwadi 28-Feb-14 15:57pm    
thank you so much dr.
Hi,

It depends... If your field type in database is a DATETIME, you can retrieve the current datetime using SQL SERVER's function GETDATE().
SQL
INSERT INTO MyTable (MyField) 
VALUES (GETDATE())


If your field type in database is a DATE, you could do it like this:
SQL
INSERT INTO MyTable (MyField) 
VALUES (CAST(GETDATE() AS TIME))
 
Share this answer
 
v3
Comments
Manish Dalwadi 28-Feb-14 15:57pm    
thank you so much dr.
Andrius Leonavicius 28-Feb-14 16:02pm    
You're welcome.
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900