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 |
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2011-06-22 : 10:05:29
|
I have a datetime field to store the time. My user wants to select the time in 15 minute intervals from a dropdownlist. So, I bind my (web) dropdownlist to this sp which displays it as 12:00, 12:15 etc etcSELECT *, LEFT(right(CONVERT(VARCHAR(30),TI_Time,108),8),5) as "ShortTime" from tbl_TimeMy question is, when I save the selected time back to the sql table how do I convert 12:00 back to 1900-01-01 12:00:00.000 |
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-06-22 : 10:20:23
|
Just convert it to datetime:select cast('12:15' as datetime)Here's a shorter query that does the same as what you posted:select *, CONVERT(char(5), TI_Time, 8) [ShortTime] from tbl_Time |
|
|
Pinto
Aged Yak Warrior
590 Posts |
Posted - 2011-06-22 : 11:01:24
|
Thanks for that but do I convert it in my stored procedure which updates my table or in my asp.net code ? |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-06-22 : 11:27:44
|
Probably easier to do in the stored procedure. |
|
|
jcelko
Esteemed SQL Purist
547 Posts |
Posted - 2011-06-23 : 00:39:12
|
>> My question is, when I save the selected time back to the sql table how do I convert 12:00 back to 1900-01-01 12:00:00.000 <<Did you know that we now have a TIME data type, so you don't have to this silly, expensive coding any more?--CELKO--Books in Celko Series for Morgan-Kaufmann PublishingAnalytics and OLAP in SQLData and Databases: Concepts in Practice Data, Measurements and Standards in SQLSQL for SmartiesSQL Programming Style SQL Puzzles and Answers Thinking in SetsTrees and Hierarchies in SQL |
|
|
|
|
|
|
|