How to get current system date time in SQL Server?
First thing which comes to many users is using following script.
SELECT GETDATE() AS CurrentDateTime
Above method is not the only method to retrieve the current system date time for SQL Server. SQL Server 2008 has many different function which provides current system date time in different format and little difference in details.
SELECT 'SYSDATETIME' AS FunctionName, SYSDATETIME() AS DateTimeFormat UNION ALL SELECT 'SYSDATETIMEOFFSET', SYSDATETIMEOFFSET() UNION ALL SELECT 'SYSUTCDATETIME', SYSUTCDATETIME() UNION ALL SELECT 'CURRENT_TIMESTAMP', CURRENT_TIMESTAMP UNION ALL SELECT 'GETDATE', GETDATE() UNION ALL SELECT 'GETUTCDATE', GETUTCDATE()
In SQL Server 2008, use any of the above function depending on your need.
Quick Video on the same subject
[youtube=http://www.youtube.com/watch?v=BL5GO-jH3HA]Reference : Pinal Dave (https://blog.sqlauthority.com)
39 Comments. Leave new
i want a qurey that minus system date and my date in data base like i want to use it on searching select * from emp where systemdate-mydate>=120days
can you plz tell me the qurey for that i am confused how to minus sysdate and mydate
mydate is my column name kindly mail me the solution
select * from table
where datecol>=dateadd(day,120,getdate())
Hi,i made databse is in vusualstudio 2010 i want to get date automatically from my system without entering date manually in text box.i need to get date automatically from system and store it in databse with other enteries……………….
please tell me how to do it???????
Thanks for this post. I didn’t get a chance yet to work on SQL Server 2008 or above. Should try it in future.
SELECT ‘FUNCTION’,CAST( {fn NOW()} AS DATETIME)
SELECT ‘FUNCTION’,CAST( GETDATE() AS DATETIME)
How to get system’s date format using sql statement?
DBCC useroptions
hello sir this is chandru i have developed chit fund software i need to make autoupdated when purticular date changed to next date kindly help me sir
i am not understand