Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getdate() question 1

Status
Not open for further replies.

aldi

IS-IT--Management
May 10, 2002
421
CA
When I use getdate() it gives me the date and time, but I only need the date.

Is there another function that gives me the date only?

Please help!
 
No there is not. You have to convert the output to the format that you need.

Code:
select convert(datetime, convert(varhcar(10), getdate(), 101))

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Thanks a lot Mr. Denny!!!

What the 101 parameter means? I found a post where they mention some other parameters like 102, 103 and 1 for the convert function.

Thanks again and have a wonderful day!
 
Styles

101 - USA - MM/DD/YYYY
 
It's the style. In this case the actual style isn't important since we are converting back to the datetime format. It's simply used to strip off the time where we then convert back to datetime which is actually today's date at midnight (SQL requires that the time be included as part of the datatype definetion).

SQL Server 2008 is supose to give us the DATE and TIME data types, however they have not yet appeared in the current CTP releases.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
aldi,

Check out FORUM183, it is for Microsoft SQL Server: Programming. Once there, go to the FAQs and find the ones for DATETIME Tips & Tricks.

-SQLBill

Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top