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.
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 temp11but when i am tyring to update in the temp11 table using the below query...update temp11set datecolumn = convert (varchar, datecolumn,111)i am getting date and time as well like...2008-01-14 00:00:00.0002008-01-14 00:00:00.0002008-01-14 00:00:00.0002008-01-14 00:00:00.000i only want the date portion in my updated new table.....any suggestions plzzzzzzzzzis it poss thru any sql query???or shud be done in the front end only??? |
|
X002548
Not Just a Number
15586 Posts |
|
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 RupsisGranite Peak SystemsPhone: 406-672-8292Email: trupsis@granitepeaksys.comLinkedIn: www.linkedin.com/in/trupsis |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-01 : 10:22:40
|
1 Always use proper DATETIME datatype2 Let front end do the formationMadhivananFailing to plan is Planning to fail |
|
|
sql9.babu
Starting Member
21 Posts |
Posted - 2008-02-01 : 20:35:11
|
hi,try thisset datecolumn = convert(varchar(9),datecolumn,101)by sql9 |
|
|
|
|
|
|
|