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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How to get the date part only and not time

Author  Topic 

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2007-09-28 : 09:26:27
Hi All,

I know this question sound childish. But I am in middle of something, and cannot find the answere in books online.

Q)How to get the date part of a following format datetime.

2005-12-28 00:00:00


I want to return 2005-12-28 only in this example.

What should I use DATEPART() or convert() & how?

Please help.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-09-28 : 09:28:57
[code]select Left(convert(varchar(10), getdate(), 120), 10)[/code]

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

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2007-09-28 : 09:30:45
zeeshan, the example you gave already is truncated to a whole date value. If you are talking about only displaying the date portion, that logic belongs in your presentation layer. Not the database.

e4 d5 xd5 Nf6
Go to Top of Page

zeeshan13
Constraint Violating Yak Guru

347 Posts

Posted - 2007-09-28 : 09:35:47
harsh_athalye,

Now I remember. Thanks for the help.

blindman,
I am dealing with Database only. Thanks for the feedback.


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-28 : 09:36:25
quote:
Originally posted by zeeshan13

Hi All,

I know this question sound childish. But I am in middle of something, and cannot find the answere in books online.

Q)How to get the date part of a following format datetime.

2005-12-28 00:00:00


I want to return 2005-12-28 only in this example.

What should I use DATEPART() or convert() & how?

Please help.


As said, do the formation at front end if you want to show formatted dates there

Madhivanan

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

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2007-09-28 : 12:19:42
quote:
Originally posted by zeeshan13


blindman,
I am dealing with Database only. Thanks for the feedback.

Then that is a problem, because a database is not an application.

e4 d5 xd5 Nf6
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-09-28 : 14:47:36
"But I am in middle of something, and cannot find the answere in books online."

Always worth a look in the FAQ:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=Getting%20the%20date%20portion%20of%20a%20datetime%20value

Kristen
Go to Top of Page
   

- Advertisement -