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
 datetime datatype probs....

Author  Topic 

raaj
Posting Yak Master

129 Posts

Posted - 2008-01-30 : 13:23:25
when i update i want only date portion tp be displayed from datetime datatype...
create table temp11 (datecolumn datetime)
insert into temp11 values (getdate ())
insert into temp11 values (getdate ())
insert into temp11 values (getdate ())
insert into temp11 values (getdate ())

now when i am running this query,i am getting what i want...
select convert (varchar, datecolumn,111) from temp11

but when i am tyring to update in the temp11 table using the below query...

update temp11
set datecolumn = convert (varchar, datecolumn,111)

i am getting date and time as well like...
2008-01-14 00:00:00.000
2008-01-14 00:00:00.000
2008-01-14 00:00:00.000
2008-01-14 00:00:00.000

i only want the date portion in my updated new table.....
any suggestions plzzzzzzzzz
is it poss thru any sql query???or shud be done in the front end only???

X002548
Not Just a Number

15586 Posts

Posted - 2008-01-30 : 13:39:30
You'll have to wait for SQL Serrver 2008

The time is always stored with the date

But when you select it, you can just display the date using 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

tprupsis
Yak Posting Veteran

88 Posts

Posted - 2008-01-30 : 13:44:26
The datetime data type in SQL Server always stores both the date and time. If time is not specified, SQL Server automatically assigns 00:00:00.00.000 like you see. Technically, SQL Server is doing you a favor, because your UPDATE statement actually tries to update a datetime column to a varchar value. This should throw an error, but SQL Server just handles it and updates the date with the default "no time" value.

Generally, you'll handle stripping off the time information when you pull data from the database. If you insist on having a column with the date value only, you'll have to use a varchar field. But then you'll lose the ability to do date arithmetic and sorting will be wrong.

Tom Rupsis
Granite Peak Systems
Phone: 406-672-8292
Email: trupsis@granitepeaksys.com
LinkedIn: www.linkedin.com/in/trupsis
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-01-30 : 13:44:27
for more info and how-TOs:
Take a look at some of the items in this section: "Datatypes - Dates"
of this topc:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210

Be One with the Optimizer
TG
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-01 : 10:22:40
1 Always use proper DATETIME datatype
2 Let front end do the formation

Madhivanan

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

sql9.babu
Starting Member

21 Posts

Posted - 2008-02-01 : 20:35:11
hi,
try this

set datecolumn = convert(varchar(9),datecolumn,101)


by sql9

Go to Top of Page
   

- Advertisement -