Solved

Is getdate() the same as CURRENT_TIMESTAMP in a query?

Posted on 2003-12-08
5
3,627 Views
Last Modified: 2008-02-01
There are not real queries: ItemDate is a datetime column

SELECT * FROM Items WHERE ItemDate > CURRENT_TIMESTAMP
SELECT * FROM Items WHERE ItemDate > getdate()

Also, if you have a DateTime field, can you set it's default to be CURRENT_TIMESTAMP? Or should you use getdate() as it's default value?

I am understand the difference between the datetime column type and the timestamp column type, but I was wondering about the CURRENT_TIMESTAMP variable and if you can use it the same as getdate() in calculations etc.
0
Comment
Question by:Stingeth
5 Comments
 
LVL 4

Expert Comment

by:dasari
ID: 9901552
yes! they both are same buddy!

Follow the link for extra documentation from msdn of microsoft

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_cr-cz_60mo.asp
0
 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 9901555
Yes. There are both same.

Namasi
0
 
LVL 4

Expert Comment

by:dasari
ID: 9901556
u can also create a table that uses CURRENT_TIMESTAMP as a DEFAULT constraint

there is an example in the above link on how to create one....
0
 

Expert Comment

by:siraj_pasha
ID: 9901926
Hi,

Both are same, only thing is many of they are familiar with getdate() than CURRENT_TIMESTAMP. On seeing the CURRENT_TIMESTAMP many have to confusion, whether it wld give only the Timestamp (without date). So U can be clear, just check this example taken from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_cr-cz_60mo.asp page,

Use CURRENT_TIMESTAMP as a DEFAULT constraint
This example creates a table that uses CURRENT_TIMESTAMP as a DEFAULT constraint for the sales_date column of a sales row.

USE pubs
GO
CREATE TABLE sales2
(
 sales_id int IDENTITY(10000, 1) NOT NULL,
 cust_id  int NOT NULL,
 sales_date datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
 sales_amt money NOT NULL,
 delivery_date datetime NOT NULL DEFAULT DATEADD(dd, 10, GETDATE())
)
GO
INSERT sales2 (cust_id, sales_amt)
   VALUES (20000, 550)

This query selects all information from the sales2 table.

USE pubs
GO
SELECT *
FROM sales2
GO

Here is the result set:

sales_id    cust_id    sales_date          sales_amt delivery_date              
----------- ---------- ------------------- --------- -------------------
10000       20000      Mar 4 1998 10:06AM  550.00    Mar 14 1998 10:06AM

(1 row(s) affected)

Rgds,
Pasha S...

0
 
LVL 50

Accepted Solution

by:
Lowfatspread earned 125 total points
ID: 9902816
current_timestamp

is more common syntax across all types of Database system...
and a timestamp is again usually recognised as a datetime  in other systems...


microsodt like to use things like now() , getdate()

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Syntax Error in Query 7 30
Optimizing a query 3 33
SQL FUll Text Not returning any results 2 15
Error running stored procedure 11 14
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now