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
 how to get only date from datetime ??????

Author  Topic 

samsun125
Yak Posting Veteran

63 Posts

Posted - 2009-09-25 : 07:37:54
Hi all,

i am fetching admitteddate from database.but i am getting date and time but i need only date.


i need to display in mm/dd/yyyy format.

i dont want to use this statement:convert(varchar,admitteddate,101)
is there any other way getting only date with out converting varchar

if anybody knows please help me

regards
rama

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-09-25 : 07:51:39
No

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-09-25 : 07:53:14
Not unless you are using SQL 2008.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-25 : 08:03:24
quote:
Originally posted by samsun125

Hi all,

i am fetching admitteddate from database.but i am getting date and time but i need only date.


i need to display in mm/dd/yyyy format.

i dont want to use this statement:convert(varchar,admitteddate,101)
is there any other way getting only date with out converting varchar

if anybody knows please help me

regards
rama


Where do you want to show converted dates?

Madhivanan

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

samsun125
Yak Posting Veteran

63 Posts

Posted - 2009-09-25 : 08:10:53
i have to display admitteddate in gridview.

is there any other way
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-25 : 08:13:04
quote:
Originally posted by samsun125

i have to display admitteddate in gridview.

is there any other way


Use format function in .NET
It should be something like

date_col.toString("MM/dd/yyyy")

Madhivanan

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

winterh
Posting Yak Master

127 Posts

Posted - 2009-09-25 : 08:57:18
DatePart() ??

[ /fail at query]
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-25 : 09:09:03
quote:
Originally posted by winterh

DatePart() ??

[ /fail at query]


Using datepart how would you format without it making a varchar?

Madhivanan

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

winterh
Posting Yak Master

127 Posts

Posted - 2009-09-25 : 09:16:16
Valid point. I newbed. (like always)

[ /fail at query]
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-25 : 09:17:06
quote:
Originally posted by winterh

Valid point. I newbed. (like always)

[ /fail at query]




Madhivanan

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

weipublic
Starting Member

19 Posts

Posted - 2009-09-25 : 22:15:53
Following can get Date from DateTimeColumn

CONVERT(DATETIME, DATEDIFF(d, 0, DateTimeColumnName ))
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-09-25 : 23:18:40
Hi, see this link

http://www.sql-server-helper.com/tips/date-formats.aspx

Go to Top of Page
   

- Advertisement -