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
 Regarding DateTime datatype

Author  Topic 

soori457
Yak Posting Veteran

85 Posts

Posted - 2009-01-07 : 09:22:09
Hai All,

I created a column Dt of datatype DateTime.

I inserted a value '01/07/2009'

when I retrieved data, then it is like this

Dt
2009-01-07 00:00:00.000

But I want to insert only date, but not time
ex:

Dt
2009-01-07

Please help me. is it possible

Suresh Kumar

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-07 : 09:25:12
No. Datetime datatype always includes the time portion too.
It is a presentation issue to get rid of the time portion.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-07 : 09:26:03
SELECT CONVERT(VARCHAR(10), dt, 120)
FROM Table1



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2009-01-07 : 09:26:25
the datatype you created is DATETIME i.e. date and time. you cannot have just the date on it's own unless you are using SQL2008, then you can use DATE datatype

Em
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-07 : 09:42:38
quote:
Originally posted by soori457

Hai All,

I created a column Dt of datatype DateTime.

I inserted a value '01/07/2009'

when I retrieved data, then it is like this

Dt
2009-01-07 00:00:00.000

But I want to insert only date, but not time
ex:

Dt
2009-01-07

Please help me. is it possible

Suresh Kumar


You shouldnt be concerned about timepart being stored in your table along with date as thats the way in which sql server stored datetime data. you can always make use of functions available in your front end application to show data in format you want. SQL Server is not meant for performing formatting of data.
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-07 : 09:45:58
try this
select left('2009-01-07 00:00:00.000',10)
select substring('2009-01-07 00:00:00.000',1,10)
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-07 : 09:48:29
bklr, you are so wrong.
Original poster wrote he already had a DATETIME column. Not a varchar column.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-07 : 09:57:16
k peso,

select convert(datetime,left('2009-01-07 00:00:00.000',10))
select convert(datetime,substring('2009-01-07 00:00:00.000',1,10))
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2009-01-07 : 10:00:37
wow
quote:
Originally posted by bklr

k peso,

select convert(datetime,left('2009-01-07 00:00:00.000',10))
select convert(datetime,substring('2009-01-07 00:00:00.000',1,10))



Em
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-07 : 10:01:28
Yes, what is there to say?
Also read this http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=117337


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2009-01-07 : 10:02:54
i think i need a cup of tea

Em
Go to Top of Page
   

- Advertisement -