Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Current date

Author  Topic 

Wouter Benoit
Starting Member

23 Posts

Posted - 2007-06-26 : 03:48:13

Hello,

I'm new to SQL server and the SQL language itself and I'm having a bit of problem.
Is it possible to obtain the current date from the system?
Something like 'sysdate' or anything like that.
I want to compare the current date with a date stored in the database but I can't seem to find the wright SQL server keyword, or is there none?

Many thanks

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-26 : 03:50:58
You need to use GETDATE() function.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Wouter Benoit
Starting Member

23 Posts

Posted - 2007-06-26 : 03:58:17
Thanks a lot!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-26 : 08:45:37
Note that getdate() includes Time as well so when you query against a date you need to take that into consideration

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

siba94
Starting Member

3 Posts

Posted - 2007-07-09 : 03:48:44
I AM TRYING TO FIND DATEDIFF BETWEEN A USER TABLE FIELD & SYSTEM DATE (FOR USING IN A VIEW),
---
DATEDIFF(DAY,CAST(LEFT(SUBSTRING(LTRIM(STR(SALFLDG110.TRANS_DATE)),5,2)+'-'+SUBSTRING(LTRIM(STR(SALFLDG110.TRANS_DATE)),7,2)+'-'+
SUBSTRING(LTRIM(STR(SALFLDG110.TRANS_DATE)),1,4),10) AS SMALLDATETIME), '05/31/2007') AS 'AGING',
----
HERE HOW DO I REPLACE '05/31/2007' WITH THE SYSTEM DATE ??

THANKS FOR THE HELP
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-09 : 03:52:26
What is the data type for TRANS_DATE ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-09 : 05:17:09
Datediff(day,trasdate,getdate())

if transdate is of proper datetime datatype

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -