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 |
|
kodali_sk
Starting Member
3 Posts |
Posted - 2008-10-29 : 14:38:31
|
| Hello,In a table, I have two date columns: Start_Date and End_Date.Suppose Start_Date has value: 2008-10-30 13:00:00.000 End_Date has value: 2008-10-30 16:00:00.000From these values, I want a string which is in the format:10/28/2008 1.00PM - 4.00PMCan someone please help me how to do it in SQL.Thank you. |
|
|
hanbingl
Aged Yak Warrior
652 Posts |
Posted - 2008-10-29 : 14:40:45
|
| what if the end date is a different date? |
 |
|
|
kodali_sk
Starting Member
3 Posts |
Posted - 2008-10-29 : 14:44:26
|
| For my purpose, start date and end date are always going to be same. Only time differs. |
 |
|
|
hanbingl
Aged Yak Warrior
652 Posts |
Posted - 2008-10-29 : 14:59:23
|
| [code]declare @start_date datetimedeclare @end_date datetimeset @start_date = '2008-10-30 13:00:00.000'set @end_date = '2008-10-30 16:00:00.000'select convert(varchar(10), @start_date,101)+right(convert(varchar(20), @start_date,0),7)+'-'+right(convert(varchar(20), @end_date,0),7)-------------------------- 10/30/2008 1:00PM - 4:00PM(1 row(s) affected)[/code] |
 |
|
|
kodali_sk
Starting Member
3 Posts |
Posted - 2008-10-29 : 15:01:35
|
| Awesome.... this is exactly what I wanted. Thank you so much :) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-30 : 03:56:09
|
| Where do you want to show formatted dates?If you use front end application, do formation thereMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|