SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

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

raaj
Posting Yak Master

128 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???

X002548
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


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

USA
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
Email: trupsis@granitepeaksys.com
LinkedIn: www.linkedin.com/in/trupsis
Go to Top of Page

TG
Flowing Fount of Yak Knowledge

USA
6062 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:
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

India
22772 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

Madhivanan

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

sql9.babu
Starting Member

USA
21 Posts

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

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


by sql9

Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.06 seconds. Powered By: Snitz Forums 2000