SQLUSA.com
SQL SERVER 2008 GRAND SLAM
FREE TRIAL  CLICK HERE TO ORDER  SEARCH
SQL JOBS SQL Server Training Scripts JOB BANK
  SQL Server 2008 Training Scripts  
  SQL Server 2005 Training Scripts  
News SQL Server Articles SQL Format

How to implement SQL NOW() functionality with GETDATE()?

Execute the following Microsoft SQL Server T-SQL programming script in SSMS Query Editor to demonstrate the SQL NOW equivalent functions.

-- SQL NOW() function: Current date & time - T-SQL equivalent: getdate()

SELECT TOP (5) ProductID, ProductName=Name, ListPrice,

               GETDATE() as PerDate

FROM AdventureWorks2008.Production.Product

WHERE ListPrice > 0.0

ORDER BY NEWID()

/*

ProductID   ProductName             ListPrice   PerDate

847   Headlights - Dual-Beam        34.99       2016-07-01 07:14:32.393

984   Mountain-500 Silver, 40       564.99      2016-07-01 07:14:32.393

837   HL Road Frame - Black, 62     1431.50     2016-07-01 07:14:32.393

880   Hydration Pack - 70 oz.       54.99       2016-07-01 07:14:32.393

724   LL Road Frame - Black, 62     337.22      2016-07-01 07:14:32.393

*/

 

-- SQL NOW() function - ANSI SQL equivalent: CURRENT_TIMESTAMP

SELECT TOP (3) ProductID, ProductName=Name, ListPrice,

               CURRENT_TIMESTAMP as PerDate

FROM AdventureWorks2008.Production.Product

WHERE ListPrice > 0.0

ORDER BY NEWID()

/*

ProductID   ProductName             ListPrice   PerDate

763   Road-650 Red, 48              782.99      2016-07-01 07:15:40.120

794   Road-250 Black, 48            2443.35     2016-07-01 07:15:40.120

836   ML Road Frame-W - Yellow, 48  594.83      2016-07-01 07:15:40.120

*/

Order SQL 2008 GRAND SLAM Today!
SQLUSA.com Home Page
SQL Server Training at www.sqlusa.com.
SQL Server 2008 Video Training at www.sqlusa.com.
SQL Server 2005 Training Videos at www.sqlusa.com.
Microsoft SQL Server 2000 Training Videos at www.sqlusa.com.

FREE SQL & Business Intelligence / OLAP Short Videos on YOUTUBE.com

Microsoft Community Contributor 2011
Invest in Your SUCCESS!

Search SQLUSA FREE SQL Server Articles & FREE T-SQL Scripts


Copyright 2005-2011, SMI Corp. All Rights Reserved.

SQL Server 2012 is a program product of Microsoft Corporation.
SQL Server 2008 is a program product of Microsoft Corporation.
SQL Server 2005 is a program product of Microsoft Corporation.
SQL Server 2000 is a program product of Microsoft Corporation.