Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 datetime datatype probs....
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

129 Posts

Posted - 01/30/2008 :  13:23:25  Show Profile  Reply with Quote
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???

Not Just a Number

15586 Posts

Posted - 01/30/2008 :  13:39:30  Show Profile  Reply with Quote
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



Hint: Want your questions answered fast? Follow the direction in this link

Add yourself!

Go to Top of Page

Yak Posting Veteran

88 Posts

Posted - 01/30/2008 :  13:44:26  Show Profile  Visit tprupsis's Homepage  Send tprupsis a Yahoo! Message  Reply with Quote
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
Go to Top of Page

Flowing Fount of Yak Knowledge

6065 Posts

Posted - 01/30/2008 :  13:44:27  Show Profile  Reply with Quote
for more info and how-TOs:
Take a look at some of the items in this section: "Datatypes - Dates"
of this topc:

Be One with the Optimizer
Go to Top of Page

Premature Yak Congratulator

22864 Posts

Posted - 02/01/2008 :  10:22:40  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
1 Always use proper DATETIME datatype
2 Let front end do the formation


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

Starting Member

21 Posts

Posted - 02/01/2008 :  20:35:11  Show Profile  Reply with Quote
try this

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

by sql9

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000