| Author |
Topic |
|
pushp82
Yak Posting Veteran
83 Posts |
Posted - 2012-05-16 : 08:17:54
|
| Hi Friends,I have to parameter as time1 - 10:43 and time2 -12:30, time1 - 14:20 and time2 -23:30, I need the output on 15 minute interval like:10:4311:0011:1511:3011:4512:0012:1512:3014:2014:30and upto 23:30How to do this. Please ASAP.Thanks,Pushkar |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-05-16 : 08:37:24
|
this is not 15 mins interval.10:4311:00Please explain your logic KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-05-16 : 08:40:27
|
| What is the logic for skipping 10:45, but not skipping 14:30? |
 |
|
|
pushp82
Yak Posting Veteran
83 Posts |
Posted - 2012-05-16 : 09:12:43
|
| U r right sunita, 10:45 should not have been skiped. like if this is 12:09 then second return would be 12:1512:0912:1512:30and then 15 minute intervalThanks, |
 |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-05-16 : 10:04:36
|
How are you given the parameters? In a table, or as variables? Here is an example of how you can write a query, assuming you have variables that define the start time and end time.DECLARE @startTime TIME, @endTime TIME;SET @startTime = '10:43';SET @endTime = '12:30';;WITH N(n) AS (SELECT 1 UNION ALL SELECT n+1 FROM N WHERE N < 50)SELECT @startTime AS T UNION ALLSELECT CAST(DATEADD(minute,15*n+DATEDIFF(minute,0,@startTime)/15*15,0) AS TIME)FROM NWHERE CAST(DATEADD(minute,15*n+DATEDIFF(minute,0,@startTime)/15*15,0) AS TIME) <= @endTime; |
 |
|
|
pushp82
Yak Posting Veteran
83 Posts |
Posted - 2012-05-17 : 02:44:00
|
| You are awesome and that worked for me thanks, but I have another issue that in case if time passed Midnights 24:00 then I have to continue like if end time is 02:15 AM and start time is 10:00PM then start from 10:00 and split up to 02:15.I'm supplying parameter from table |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2012-05-17 : 23:56:13
|
| IF (cast(@TIMEFROM as int)>cast(@TIMETO as int)? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-05-18 : 00:19:20
|
[code]DECLARE @startTime datetime = '22:45', @endTime datetime = '03:31'if @endTime < @startTimebegin select @endTime = dateadd(day, 1, @endTime)end; with rcte as( select [time] = dateadd(minute, ceiling(datediff(minute, 0, @startTime) / 15.0) * 15, 0) union all select [time] = dateadd(minute, 15, [time]) from rcte where dateadd(minute, 15, [time]) <= @endTime)select [time] = @startTimeunionselect *from rcteunion select [time] = @endTimeorder by [time][/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
pushp82
Yak Posting Veteran
83 Posts |
Posted - 2012-05-18 : 01:43:15
|
| thanks khtan, can we show date with time actually current date and change date after 12:00 PM? How? |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-05-18 : 02:37:24
|
quote: Originally posted by pushp82 thanks khtan, can we show date with time actually current date and change date after 12:00 PM? How?
Don't really get what you mean here .. Can you elaborate further or perhaps with some sample data ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
pushp82
Yak Posting Veteran
83 Posts |
Posted - 2012-05-18 : 05:47:13
|
| Hi khtan ,I'm almost done with but the issue left is I have a column contain values as 00.4500.3001.1501.2000.20as decimal (18,2)I need to chnage this time to minutes(MM) and then return the values greater than that value so the issue left is convert these values to minutecan u help me ASAPthanks |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-05-18 : 06:34:00
|
[code]declare @d decimal(18,2)select @d = 01.15select @d, dateadd(minute, @d * 100 % 100, dateadd(hour, floor(@d), 0))[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|