Solved

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

Posted on 2003-12-08
5
3,634 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

730 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