SQL NOW() and SQL-Server GETDATE() Function



SQL NOW() and SQL-Server GETDATE() Function

NOW() – The sql function NOW() is returns current system date and time.

The sql syntax of NOW() is :

SELECT NOW() FROM Table_Name

 

In SQL Server we use GETDATE() function to get current date and time.

The syntax of GETDATE() is :

SELECT GETDATE();
SELECT GETDATE() FROM Table_Name
sql now() and getdate()
Use SQL NOW() and GETDATE() Function

Let’s understand SQL NOW() and GETDATE() function with an example :

We have SQL Table StudentMst with below column.

SELECT * FROM StudentMst

ID Name City Pincode Mobile
1 Meera Bombay 380022 7874555555
2 Rahul Surat 352200 7874444444
3 Jayesh Ahmedabad 352200 7874333333
4 Dhvanish Bombay 380022 7874111111
5 Reena Baroda 352222 7874666666
6 Veera Baroda 352222 7874121212

SELECT ID, Name, City, Pincode, GETDATE() as DATE FROM StudentMst

ID Name City Pincode DATE
1 Meera Bombay 380022 2015-07-29 21:51:18.920
2 Rahul Surat 352200 2015-07-29 21:51:18.920
3 Jayesh Ahmedabad 352200 2015-07-29 21:51:18.920
4 Dhvanish Bombay 380022 2015-07-29 21:51:18.920
5 Reena Baroda 352222 2015-07-29 21:51:18.920
6 Veera Baroda 352222 2015-07-29 21:51:18.920

SELECT GETDATE() AS DATE

DATE
2015-07-29 21:51:18.920

Leave a Reply

Your email address will not be published. Required fields are marked *