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
 Date From Date/Time Field

Author  Topic 

pgmr1998
Yak Posting Veteran

66 Posts

Posted - 2010-08-16 : 14:30:04
I am pulling a field that is in date/time format using a Select stmt. How can I retrieve only the date portion? The field is in the format:
"yyyy-mm-dd hh:mm:ss.000"

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-16 : 14:39:15
So the Datatype is datetime? Or isn't it?

If it is

SELECT CONVERT(varchar(10),GETDATE(),112)


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

pgmr1998
Yak Posting Veteran

66 Posts

Posted - 2010-08-16 : 15:10:58
Thanks, that worked, but how can I get it to display in the format "yyyy-mm-dd" ?
It displays as yyyymmdd
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-08-16 : 15:13:12
SELECT CONVERT(varchar(10),GETDATE(),120)


Do you know what books online is?

Look up Cast and Convert

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-17 : 02:32:52
quote:
Originally posted by pgmr1998

Thanks, that worked, but how can I get it to display in the format "yyyy-mm-dd" ?
It displays as yyyymmdd


Where do you want to show formatted dates?. If you use front end application, do formation there

Madhivanan

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

- Advertisement -