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 2005 Forums
 Transact-SQL (2005)
 Problem with Date Value Insertion

Author  Topic 

mounikakala
Starting Member

14 Posts

Posted - 2008-08-16 : 19:18:16
Hi,

I have problem, I have a Column with Datetime.

When I insert getdate() value into that, the "2008-08-16 18:13:52.503"

is inserted into that. But I Need only the Value such as
"2008-08-16" or "2008/08/16" to be inserted into that Column.

I can Convert it using
CONVERT(varchar(10), GETDATE(), 101)
CONVERT(CHAR(10),GETDATE(),103)

but they convert my Datetime into Varchar where as my Column is a Datetime Column.

In short I need to Store the Date Value as "2008-08-16" or "2008/08/16" but not with Mins, hours etc.

Can it be possible.

Thanks
Mounika

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-16 : 19:36:37
dateadd(day, dateadiff(day, 0, getdate()), 0)


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-08-16 : 19:46:51
In a datetime you cannot store a date value like "2008-08-16".
Try posted code from khtan - this is the best way and you will get "2008-08-16 00:00:00.000".

Webfred


Too Old to Rock 'n' Roll, Too Young to Die
Go to Top of Page

mounikakala
Starting Member

14 Posts

Posted - 2008-08-16 : 21:07:28
Thanks
Go to Top of Page
   

- Advertisement -