15 pts.
 order of evaluation in DateAdd with multiple expressions
I've spent 3 hours researching how order of evaluation would work in this expression. If @BeginTime was 16:45:00 for example, what would be the result of this expression? set @BeginTime = DateAdd(mi,-Datepart(mi,@BeginTime)-Datepart(hh,@BeginTime)*60,@BeginTime )

Software/Hardware used:
ASKED: July 21, 2009  6:53 PM
UPDATED: July 21, 2009  8:26 PM

Answer Wiki:
It should give you '00:00:00' Lets split it into smaller parts: this is the original expression: <pre>set @BeginTime = DateAdd(mi,-Datepart(mi,@BeginTime)-Datepart(hh,@BeginTime)*60,@BeginTime ) </pre> Now, let's suppose we make <pre>A = Datepart(mi,@BeginTime)</pre> and <pre>B = Datepart(hh,@BeginTime)</pre> So, our main expression is now: <pre>set @BeginTime = DateAdd(mi,-A-B*60,@BeginTime )</pre> which, is the equivalent to: <pre>set @BeginTime = DateAdd(mi,-A-<b>(</b>B*60<b>)</b>,@BeginTime )</pre> Now, let's calculate A and B. <pre>A = Datepart(mi,'16:45:00') = 45 B = Datepart(hh,'16:45:00') = 16</pre> So, we have <pre>set @BeginTime = DateAdd(mi,-45-(16*60),'16:45:00' ) = DateAdd(mi,-1005,'16:45:00' )</pre> And 1005 minutes are equal to 16 hours and 45 minutes, so the result is 0 minutes (i.e. '00:00:00').
Last Wiki Answer Submitted:  July 21, 2009  7:49 pm  by  carlosdl   63,535 pts.
All Answer Wiki Contributors:  carlosdl   63,535 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Thanks!!

 15 pts.

 

You are welcome.

Summarizing, that expression will substract the hours and minutes from the original time, and the result will be just the seconds, which in this case were 0.

 63,535 pts.