Solved

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

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

776 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