Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

How do you refer to the current date in SQL Server 2000?

How do you refer to the current date in SQL Server 2000? Reason I need to know is because I'm trying to come up with a query that will use the currentDate in a WHERE statement such as :

update tableA
Set columnA = 'whatever'
where columnB = current_Date

but I'm getting a syntax error near current_date :SICK:
[358 byte] By [Matrix.net] at [2007-11-11 10:06:29]
# 1 Re: How do you refer to the current date in SQL Server 2000?
It's the function GETDATE.
pclement at 2007-11-11 23:43:26 >
# 2 Re: How do you refer to the current date in SQL Server 2000?
Please try searching the Web before posting: http://www.google.com/search?q=sql+server+current+date . Thanks! :-)
Phil Weber at 2007-11-11 23:44:26 >
# 3 Re: How do you refer to the current date in SQL Server 2000?
I did try searching the web , GETDATE() isnt helpful either by itself because it returns the time right down to nanoseconds. I just got word that I have to use DATEDIFF along with it but that returns an INTEGER value (I think from what I understand) and I dont get how I could use that from within setting up a JOB which is what I'm trying to do.
Matrix.net at 2007-11-11 23:45:36 >
# 4 Re: How do you refer to the current date in SQL Server 2000?
Hmm - in that case you need to ask the question that you want an answer to. What are you trying to do? Are you trying to update all records that from a given day or something?
waterjock2000 at 2007-11-11 23:46:35 >
# 5 Re: How do you refer to the current date in SQL Server 2000?
You may use the DATEPART ( http://www.google.com/search?q=sql+datepart) function in conjunction with GETDATE to obtain the year, month, day, etc.
Phil Weber at 2007-11-11 23:47:34 >
# 6 Re: How do you refer to the current date in SQL Server 2000?
This would help you return current date as a date type

dateAdd(dd, datediff(dd, 0, GetDate()), 0)
Gumtree at 2007-11-11 23:48:30 >
# 7 Re: How do you refer to the current date in SQL Server 2000?
You may also find this helpful: http://weblogs.sqlteam.com/jeffs/archive/2007/01/02/56079.aspx
Phil Weber at 2007-11-11 23:49:34 >
# 8 Re: How do you refer to the current date in SQL Server 2000?
thanks everyone, I did however manage to figure out the query I needed yesterday which was :

USE OnlineJobs_BackUp
GO

UPDATE AvailableJobs
SET ActiveOrPosted = 'posted'
WHERE DATEDIFF(day, postingEnds, getdate()) = 0

GO

( what it does is , at runtime it looks for the datefield "postingEnds" and sees if today's date matches the datevalue in PostingEnds column and if so , do an update query on it. ) I'm sure you guys knew but put an explenation anyways incase someone else needs this info in the future.
Matrix.net at 2007-11-11 23:50:37 >