NOW () function
NOW function returns the current date and time.
Tip: If you are using Sql Server database, use the getdate () function to get the current date and time.
SQL NOW () syntax
SELECT NOW() FROM table_name
SQL NOW () example
We have the following "Products" table:
Prod_Id | ProductName | Unit | UnitPrice |
---|---|---|---|
1 | gold | 1000 g | 32.35 |
2 | silver | 1000 g | 11.56 |
3 | copper | 1000 g | 6.85 |
Now, we want to display today's date corresponding to the name and price.
We use the following SQL statement:
SELECT ProductName, UnitPrice, Now() as PerDate FROM Products
The result set will look like this:
ProductName | UnitPrice | PerDate |
---|---|---|
gold | 32.35 | 12/29/2008 11:36:05 AM |
silver | 11.56 | 12/29/2008 11:36:05 AM |
copper | 6.85 | 12/29/2008 11:36:05 AM |