MC Press Online Forum
Welcome, Guest
Please Login or Register.    Lost Password?
Tech Tip: Elapsed Time Function (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Tech Tip: Elapsed Time Function
#113843
101communications (User)
Posts: -10
graphgraph
User Offline Click here to see the profile of this user
Tech Tip: Elapsed Time Function 5 Years, 7 Months ago Karma: 0  
I am little confused. Why would I want to write an entire procedure to do what is already available (and BETTER!) in RPG? <p>You are using Date and Time fields. Why not use a Timestamp field? This would allow to calculate elpased times less than a second (of course how accurate would these times really be??). <p>You are using the %Diff() BIF. Why not use the %Diff() against the 2 Timestamp fields directly? <p>You are using you own code to return the elapsed time in different units (Hours, Days, etc.). Why not use the optional 3rd parm on %Diff()? <p>As you can see, ALL of the functionallity you have written into your procedure are directly available by using 2 Timestamp fields (with the TIME op-code) and the %Diff() BIF. So, what's the point? <p>Brian
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#113844
Guest.Visitor (Visitor)

Birthdate:
Tech Tip: Elapsed Time Function 5 Years, 7 Months ago  
If you've already got the "From" and "To", why not just use the SUBDUR opcode, then you'll get the difference with one line of code. <p>Matt
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#113845
Guest.Visitor (Visitor)

Birthdate:
Tech Tip: Elapsed Time Function 5 Years, 7 Months ago  
What you're saying is true; however, that could be said of any user-defined function. The point of this is to take what would otherwise be a multi-step process and convert it into a format that can be used on a single EVAL statement. While this can be accomplished with SUBDUR, the function will do both date and time in one step. The tech tip itself was written in response to a question that I've heard other iSeries programmers ask. <p>Mike
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#113846
Guest.Visitor (Visitor)

Birthdate:
Tech Tip: Elapsed Time Function 5 Years, 7 Months ago  
Another way to easily compute duration given two dates and times is using builtin function %DIFF() as follows: <p><code>dur=%diff(d1+t1:d2+t2:*minutes);</code> <p>That is, you can "add" together a date value and a time value to get a timestamp value, and you can then compute the difference of the two timestamps. <p>Cheers! Hans
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#113847
Guest.Visitor (Visitor)

Birthdate:
Tech Tip: Elapsed Time Function 5 Years, 6 Months ago  
Hello, <p>why using a couple of statements, when SQL needs only one. <p>Here an example how to calulate date/time difference with embedded SQL: <p>Birgitta <p><!--mccodelink_begin--> <BR>
<!-- do not remove --> <BR>
<hr width=50 align=left><small><a href='http://www.mcpressonline.com/mc/showcode@@.6ae682ba/4' target='_blank'>Code</a></small> <BR>
<!--mccodelink_end-->
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#113842
MC Press Web Site Staff (Admin)
Admin
Posts: 1061
graphgraph
User Offline Click here to see the profile of this user
Tech Tip: Elapsed Time Function 5 Years, 6 Months ago Karma: 1  
This is a discussion about <B>Tech Tip: Elapsed Time Function</b>.<p align='center'><a href=http://www.mcpressonline.com/mc? This e-mail address is being protected from spam bots, you need JavaScript enabled to view it @.6ae678d4>Click here for the article</a>.</p>
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop
   MC-STORE.COM