SQL NOW() Function
- Previous Page SQL round()
- Next Page SQL format()
NOW() Function
The NOW function returns the current date and time.
Tip:If you are using the Sql Server database, please use the getdate() function to obtain 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 the name and price corresponding to the current date.
We use the following SQL statement:
SELECT ProductName, UnitPrice, Now() as PerDate FROM Products
The result set is similar to 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 |
- Previous Page SQL round()
- Next Page SQL format()