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 |
|
VegaLA
Starting Member
3 Posts |
Posted - 2005-01-20 : 14:33:24
|
| Hi all, can someone please assist a complete newbie in this date field problem ? I have a field in a tble named DateT and this is input by the users via a Intranet site in the format 2:30. In the table it is stored as 1/1/1900 2:30:00 PM. If the user then decides to edit the time for whatever reason it is displayed as 1/1/1900 2:30:00 PM. In Access you could run a query to shorten it to 2:30 but I know nothing of Triggers, stored procedures or whatever in SQL server so which is the best way for a beginner to automatically convert/update the date from 1/1/1900 2:30:00 PM to 2:30 ? Best regards,Mitch.......... |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-01-20 : 14:49:47
|
| You'll need to use the CONVERT function with a style. Open up SQL Server Books Online and check out the topic CONVERT. You'll see a pretty big chart of the styles that can be used for datetime data. Here's an example:select convert(varchar(20), getdate(), 108)Tara |
 |
|
|
VegaLA
Starting Member
3 Posts |
Posted - 2005-01-20 : 17:37:22
|
| Thanks Tara, I gave that a try with a trigger for the table but I got a syntax error. This is how it looks. I've not done this before so could you please show me where i've gone wrong ? CREATE TRIGGER [CorrectTime ] ON [TimeT].[tblBookingTest] FOR INSERTconvert(varchar(20), getdate(), 108)Best regards,Mitch........... |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-01-20 : 17:47:18
|
| Why do you want this in a trigger?The data will always be stored with the date portion. SQL Server does not have a separate time data type. So when you query the data, you just need to use CONVERT with a style for viewing purposes. But internally, the date is still there.Tara |
 |
|
|
VegaLA
Starting Member
3 Posts |
Posted - 2005-01-20 : 19:26:10
|
| My mistake, I thought the code you posted had to be used in a trigger. Thanks again. |
 |
|
|
|
|
|
|
|