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 |
|
joelseverich
Starting Member
34 Posts |
Posted - 2009-02-25 : 15:37:57
|
| Hiis there a way to change the format for datetime columnex. '01/01/2008 01:00:00 AM' TO only '01/01/2008'i want to keep only the date in all rows |
|
|
mfemenel
Professor Frink
1421 Posts |
Posted - 2009-02-25 : 16:09:20
|
| as far as actually storing it in a date field, no. If you wanted to store it that way you'd have to use a varchar data type. If you're pulling it out and using it for something you can convert a datetime or small datetime I think it's format 112. Convert(varchar(15),fieldname,112). If you don't care about anything past the date piece I would also suggest you change this to a smalldatetime and save 4 bytes per row.Mike"oh, that monkey is going to pay" |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
|
|
SQLforGirls
Starting Member
48 Posts |
Posted - 2009-02-26 : 03:27:40
|
| mfemenel is addressing how you display the data. bklr is addressing how you store the data.mfemenel makes a good point that you can use small datetime to save some spacebklr is pointing out that in order to effectively store only the date, you would normally choose to truncate the time portion of the incoming date, resulting in a value of '1/1/2008 00:00:00'. Storing it in that way allows you to take advantage of the date functions by keeping it in a date format, but any date comparisons would effectively ignore the time component of the date value. So if you want to find all orders that were made on 1/1/08, you can say " where order_date = '1/1/08' ".Hope that helps flesh out the situation so you can decide what works best for you. |
 |
|
|
shaggy
Posting Yak Master
248 Posts |
Posted - 2009-02-26 : 04:39:55
|
| select convert(varchar,GETDATE(),103) |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-02-26 : 06:02:20
|
Additional:SQL Server 2008 knows types for only date and only time.Webfred No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|
|
|