Source language: Translate to:

calculating time elapsed?

General questions about NeoBook

Moderator: Neosoft Support

Re: calculating time elapsed?

Postby fkapnist » Tue Dec 16, 2014 5:09 pm

yanzco wrote:if i check elapsed time between 7:45:00 to 8:24:00 it says its 79:00
correct answer should be 39 minutes


if i check 7:45 (bob time) to 9:24 (mary time)
it says 1hr 79min

correct answer should be 1hr 39min

hmmmm..

so confused, how do you get it..


Working only with hours is easy... 8 from 12 is 4

But if you have___ 12:24:32
and subtract _____08:45:51
you can't subtract 51 seconds from 32 seconds... or 45 minutes from 24 minutes... that's why it works best if everything is already in milliseconds before you determine the difference....

I'll spend more time on this tomorrow.... It is 2:AM... What time is it where you are? lol... I never realized it was so tricky to determine a simple time difference.... and we also need to consider the different time zones.



.. :roll:
User avatar
fkapnist
 
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece

Re: calculating time elapsed?

Postby fkapnist » Tue Dec 16, 2014 5:14 pm

Working only with hours is easy... 8 from 12 is 4

But if you have___ 12:24:32
and subtract _____08:45:51
you can't subtract 51 seconds from 32 seconds... or 45 minutes from 24 minutes... that's why it works best if everything is already in milliseconds before you determine the difference....

I'll spend more time on this tomorrow.... It is 2:AM... What time is it where you are? lol... I never realized it was so tricky to determine a simple time difference.... and we also need to consider the different time zones.



.. :roll:
User avatar
fkapnist
 
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece

Re: calculating time elapsed?

Postby dec » Tue Dec 16, 2014 5:19 pm

Hello,

One possible way can be using my npUtil plugin, which have various actions to work with Date and Times. For example, to calculate the hours between two specified datetimes values, we can codify something like this:

Code: Select all
.Conform our first Datetime (current year, month and day, 1 hours: 1 AM)
npEncodeDateTime "[Year]" "[MonthNum]" "[DayNum]" "1" "0" "0" "0" "[FirstDateTime]"

.Conform our second Datetime (current year, month and day, 15 hours: 3 PM)
npEncodeDateTime "[Year]" "[MonthNum]" "[DayNum]" "15" "0" "0" "0" "[SecondDateTime]"

.Obtain the hours between our first and second Datetime
npHoursBetween "[FirstDateTime]" "[SecondDateTime]" "[HoursBetween]"

.Show the hours between our first and second Datetime
AlertBox "Information" "The hour beetween two dates are: [HoursBetween]"


More Date and Time related actions can be found documented here.
.
Enhance your NeoBook applications!
.
58 plugins, 1131 actions and 233 samples
.
NeoPlugins website: www.neoplugins.com
.
User avatar
dec
 
Posts: 1663
Joined: Wed Nov 16, 2005 12:48 am
Location: Spain

Re: calculating time elapsed?

Postby yanzco » Tue Dec 16, 2014 5:20 pm

fkapnist wrote:I also found this Javascript that does exactly what you want:

Syntax: [ Download ] [ Hide ]
Using Javascript Syntax Highlighting
<html>
<head>
<script language="javascript" type="text/javascript">
function p (i)
{
        return Math.floor(i / 10) + "" + i % 10;
}

function init ()
{
        var form = document.getElementById('form');
        var date = new Date();
        var s = p(date.getMonth() + 1) + "/" + p(date.getDate()) + "/" + date.getFullYear() + " " + p(date.getHours()) + ":" + p(date.getMinutes()) + ":" + p(date.getSeconds());
        if (form.date1.value == "")
                form.date1.value = s;
        if (form.date2.value == "")
                form.date2.value = s;
}

function trunc (i)
{
        var j = Math.round(i * 100);
        return Math.floor(j / 100) + (j % 100 > 0 ? "." + p(j % 100) : "");
}

function calculate (form)
{
        var date1 = new Date(form.date1.value);
        var date2 = new Date(form.date2.value);
        var sec = date2.getTime() - date1.getTime();
        if (isNaN(sec))
        {
                alert("Input data is incorrect!");
                return;
        }
        if (sec < 0)
        {
                alert("The second date ocurred earlier than the first one!");
                return;
        }

        var second = 1000, minute = 60 * second, hour = 60 * minute, day = 24 * hour;

        form.result_h.value = trunc(sec / hour);
        form.result_m.value = trunc(sec / minute);
        form.result_s.value = trunc(sec / second);

        var days = Math.floor(sec / day);
        sec -= days * day;
        var hours = Math.floor(sec / hour);
        sec -= hours * hour;
        var minutes = Math.floor(sec / minute);
        sec -= minutes * minute;
        var seconds = Math.floor(sec / second);
        form.result.value = days + " day" + (days != 1 ? "s" : "") + ", " + hours + " hour" + (hours != 1 ? "s" : "") + ", " + minutes + " minute" + (minutes != 1 ? "s" : "") + ", " + seconds + " second" + (seconds != 1 ? "s" : "");
}
</script>
</head>

<body>
<center>
<table border="0" cellpadding="1" cellspacing="0" id="mainbg"><tr><td>

</td>
</tr>
</table>
<br>
</center>
<table border="0" cellpadding="10" cellspacing="0">
<tr>
<td width="500" valign="top" class="content">
<div align="center">
<span class="red">Days, hours, minutes, and seconds between two dates</span>
</div>

        <form id="form">
        <table cellpadding="3">
                <tr>
                        <td colspan="2" align="center">Enter values in <font color="#800000">mm/dd/yy hh:mm:ss</font> format</td>
                </tr>
                <tr>
                        <td>First date and time</td>
                        <td><input type="text" name="date1" /></td>
                </tr>
                <tr>
                        <td>Second date and time</td>
                        <td><input type="text" name="date2" /></td>
                </tr>
                <tr>
                        <td colspan="2" align="center"><input type="button" name="submit" value="Calculate" onclick="calculate(this.form)" /></td>
                </tr>
                <tr>
                        <td>Result</td>
                        <td colspan="2"><input type="text" name="result" readonly="readonly" size="40" /></td>
                </tr>
                <tr>
                        <td>In (decimal) hours</td>
                        <td colspan="2"><input type="text" name="result_h" readonly="readonly" /></td>
                </tr>
                <tr>
                        <td>In (decimal) minutes</td>
                        <td colspan="2"><input type="text" name="result_m" readonly="readonly" /></td>
                </tr>
                <tr>
                        <td>In seconds</td>
                        <td colspan="2"><input type="text" name="result_s" readonly="readonly" /></td>
                </tr>
        </table>



        </form>
<script language="JavaScript" type="text/javascript">
<!--
init();
//-->
</script>

</td></tr></table>
</body>
</html>
 
Parsed in 0.022 seconds, using GeSHi 1.0.8.10


Save it as a html page or paste it into a [BrowserLoadFromStr] object in Neobook to see how it works...

:arrow:
.






i havent tried this, but if it works, how do i let it get variables in neobook, time A and time b..
and store the answer to neobook variable?...


@fkapnist
its 8:17am here... this got me stuck so much i wasnt able to sleep ... haha


if it would be just as simple as, having the given hour and minutes only
in 24 hr format to make everything easier..

just calculating elapsed time from

7:00 to 13:25

8:20 to 16:20

18:30 to 00:15

19:00 to 3:00


no time zones..
no am pm

just hour and minutes

and everything time a and time b is in within just 24 hours...
yanzco
 
Posts: 178
Joined: Sun Jul 20, 2014 4:07 am

Re: calculating time elapsed?

Postby yanzco » Tue Dec 16, 2014 5:34 pm

@fkapnist yes the javascript works perfectly... and just the thing i wanted.. infact even more..

now, how do we let it get variables from neobook (time A and time B)
and viceversa, webbrowser result to neobook variable [timeC]
yanzco
 
Posts: 178
Joined: Sun Jul 20, 2014 4:07 am

Re: calculating time elapsed?

Postby Gaev » Tue Dec 16, 2014 5:47 pm

yanzco:

If you are using ...

[Time] ... The current time (H:M:S AM/PM)

... why not just use ...

[Time24] ... The current time in 24-hour format.
[Minute] ... The current minute.

... then ...
Code: Select all
Math "([Time24]*60) + [Minute]" "0" "[MinutesSinceMidnight1]"

... same for "[MinutesSinceMidnight2]" ... then the difference in minutes is ...
Code: Select all
If "[MinutesSinceMidnight1]" ">" "[MinutesSinceMidnight2]"
   Math "[MinutesSinceMidnight1] - [MinutesSinceMidnight2]" "0" "[MinutesDiff]"
Else
   Math "[MinutesSinceMidnight2] - [MinutesSinceMidnight1]" "0" "[MinutesDiff]"
EndIf

... and if you want it in Hours and Minutes ...
Code: Select all
Math "[MinutesDiff]/60" "0" "[WholeHours]"
Math "[MinutesDiff] - ([WholeHours]*60)" "0" "[WholeMinutes]"


If for some reason, you can not use [Time24] and [Minutes], you can parse the time in H:M:S AM/PM format ...
Code: Select all
StrParse "[TimeString]" " " "[TimePartA] "[junk]"
... [TimePartA2] contains AM or PM
If "[TimePartA2]" "=" "AM"
   SetVar "[HourComponent]" "0"
Else
   SetVar "[HourComponent]" "12"
Endif
... [TimePartA1] contains H:M:S
StrParse "[TimePartA1]" ":" "[TimePartB] "[junk]"
... [TimePartB1] contains H and ... [TimePartB2] M
Math "[HourComponent] + [TimePartB1]" "0" "[HourComponent]"
... but 12:xx PM is 12 on the 24 hour clock ... so
If "[HourComponent]" "=" "24"
   SetVar [HourComponent]" "12"
EndIf

... now, you can use [HourComponent] and [TimePartB2] to calculate [MinutesSinceMidnight2] as above.
User avatar
Gaev
 
Posts: 3738
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: calculating time elapsed?

Postby fkapnist » Tue Dec 16, 2014 6:30 pm

You can try this time difference PUB.... At least all the math functions are correct. Maybe just grab some of the form variables and display them elsewhere in your Neobook app

http://www.verticalbrowser.com/zips/TimeDifference.zip

:?

.
User avatar
fkapnist
 
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece

Re: calculating time elapsed?

Postby fkapnist » Tue Dec 16, 2014 6:49 pm

yanzco wrote:@fkapnist yes the javascript works perfectly... and just the thing i wanted.. infact even more..

now, how do we let it get variables from neobook (time A and time B)
and viceversa, webbrowser result to neobook variable [timeC]



Use these:
Code: Select all
[b]
nbSetVar

Purpose:
 This method assigns a string value to a NeoBook variable.
 
Syntax:
 window.external.nbSetVar( variable name, value )

variable name

The name of a NeoBook variable. The variable name should be surrounded by square brackets.

value

The value to assign to the variable. Must be of type string.
 
Example:
 The following HTML JScript copies the contents of two Text Boxes called "FirstName" and "LastName" to the NeoBook variables [FirstName] and [LastName]:




<script language="JScript">

function SetVars() {

  window.external.nbSetVar( '[FirstName]', mainform.FirstName.value );

  window.external.nbSetVar( '[LastName]', mainform.LastName.value );

  }

</script>
 




nbGetVar

Purpose:
 This method returns a string containing the contents of a NeoBook variable.
 
Syntax:
 value = window.external.nbGetVar( variable name )

variable name

The name of the NeoBook variable to retrieve. The variable name should be surrounded by square brackets.

value

The contents of the NeoBook variable in string format.
 
Example:
 The following HTML JScript copies the contents of NeoBook's [FirstName] and [LastName] variables to two Text Boxes called "FirstName" and "LastName":




<script language="JScript">

function GetVars() {

  mainform.FirstName.value = window.external.nbGetVar( '[FirstName]' );

  mainform.LastName.value = window.external.nbGetVar( '[LastName]' );

  }

</script>
 




nbExecAction

Purpose:
 Use this method to execute NeoBook actions.
 
Syntax:
 window.external.nbExecAction( action script )

action script

The NeoBook action to execute. Multiple actions may specified by separating them with a carriage return.[/b]



In the sample Javascript the form has no name or id. It may be easier to give it one (i.e., mainform)....

use these javascript functions to set the two times:

mainform.date1.value = window.external.nbGetVar( '[timeA]' );
mainform.date2.value = window.external.nbGetVar( '[timeB]' );

and this javascript function to get the difference variable back into Neobook:

window.external.nbSetVar( '[timeC]', mainform.result.value );




:arrow:
.
User avatar
fkapnist
 
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece

Re: calculating time elapsed?

Postby yanzco » Tue Dec 16, 2014 7:22 pm

@gaev

your code almost works... but its wrong in some other parts..
i set it to

700 to 1200 = 5 hrs >> correct
700 to 1300 = 6 hrs >> correct
700 to 2100 = 14 hrs >> correct


but somethings wrong... i dont know where but

715 to 2100 = 14 hr -15min >> almost correct -15 ? (14hr 15min correct)
715 to 2110 = 14hr -5 min >> wrong (13hr 55min correct)
715 to 2130 = 14hr 15min >> correct
715 to 2145 = 15 hr -30min >> wrong (14hr 35min correct)


so, somewhere in adding the minutes
yanzco
 
Posts: 178
Joined: Sun Jul 20, 2014 4:07 am

Re: calculating time elapsed?

Postby yanzco » Tue Dec 16, 2014 8:08 pm

In the sample Javascript the form has no name or id. It may be easier to give it one (i.e., mainform)....

use these javascript functions to set the two times:

mainform.date1.value = window.external.nbGetVar( '[timeA]' );
mainform.date2.value = window.external.nbGetVar( '[timeB]' );

and this javascript function to get the difference variable back into Neobook:

window.external.nbSetVar( '[timeC]', mainform.result.value );




:arrow:
.



sadly, i dont know how to javascript that much, i dont know where to place all those things..
yanzco
 
Posts: 178
Joined: Sun Jul 20, 2014 4:07 am

Re: calculating time elapsed?

Postby yanzco » Tue Dec 16, 2014 9:31 pm

i think this is the solution... since gaev's formula got the minutes diff.. it computes for
the minutes in decimal..


How to convert decimal hours to time format:

Convert 2.88 hours to hh:mm:ss

2.88 hours can be broken down to 2 hours plus 0.88 hours - 2 hours
0.88 hours * 60 minutes/hour = 52.8 minutes - 52 minutes
0.8 minutes * 60 seconds/minute = 48 seconds - 48 seconds
02:52:48

How to convert decimal minutes to time format:

Convert 78.6 minutes to hh:mm:ss

78.6 minutes can be converted to hours by dividing 78.6 minutes / 60 minutes/hour = 1.31 hours
1.31 hours can be broken down to 1 hour plus 0.31 hours - 1 hour
0.31 hours * 60 minutes/hour = 18.6 minutes - 18 minutes
0.6 minutes * 60 seconds/minute = 36 seconds - 36 seconds
01:18:36


let me see if its all correct..
yanzco
 
Posts: 178
Joined: Sun Jul 20, 2014 4:07 am

Re: calculating time elapsed?

Postby yanzco » Tue Dec 16, 2014 10:19 pm

Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5.80
ObjectType=14
Name=WebBrowser1
X=450
Y=0
W=348
H=510
Anchor=0
VarName=[WebBrowser1Status]
TitleVarName=[WebBrowser1Title]
URLVarName=[WebBrowser1Addr]
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Space Bd BT
FontSize=12
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=1
ObjectType=3
Name=PushButton1
X=580
Y=520
W=80
H=30
Anchor=0
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=BrowserLoadFromStr "WebBrowser1" "<html>|<head>|<script language=[#34]javascript[#34] type=[#34]text/javascript[#34]>||function p (i)|{|   return Math.floor(i / 10) + [#34][#34] + i % 10;|}||function init ()|{|   var form = document.getElementById('form');|   var date = new Date();|   var s = p(date.getMonth() + 1) + [#34]/[#34] + p(date.getDate()) + [#34]/[#34] + date.getFullYear() + [#34] [#34] + p(date.getHours()) + [#34]:[#34] + p(date.getMinutes()) + [#34]:[#34] + p(date.getSeconds());|   if (form.date1.value == [#34][#34])|      form.date1.value = s;|   if (form.date2.value == [#34][#34])|      form.date2.value = s;|}||function SetVars()|{|  window.external.nbSetVar( '[TimeAA]', mainform.TimeAA.value );|  window.external.nbSetVar( '[TimeBB]', mainform.TimeBB.value );|}||function GetVars()|{|  mainform.TimeAA.value = window.external.nbGetVar( '[TimeAA]' );|  mainform.TimeBB.value = window.external.nbGetVar( '[TimeBB]' );|}|||function trunc (i)|{|   var j = Math.round(i * 100);|   return Math.floor(j / 100) + (j % 100 > 0 ? [#34].[#34] + p(j % 100) : [#34][#34]);|}||function calculate (form)|{|   var date1 = new Date(form.date1.value);|   var date2 = new Date(form.date2.value);|   var sec = date2.getTime() - date1.getTime();|   if (isNaN(sec))|   {|      alert([#34]Input data is incorrect![#34]);|      return;|   }|   if (sec < 0)|   {|      alert([#34]The second date ocurred earlier than the first one![#34]);|      return;|   }||   var second = 1000, minute = 60 * second, hour = 60 * minute, day = 24 * hour;||   form.result_h.value = trunc(sec / hour);|   form.result_m.value = trunc(sec / minute);|   form.result_s.value = trunc(sec / second);||   var days = Math.floor(sec / day);|   sec -= days * day;|   var hours = Math.floor(sec / hour);|   sec -= hours * hour;|   var minutes = Math.floor(sec / minute);|   sec -= minutes * minute;|   var seconds = Math.floor(sec / second);|   form.result.value = days + [#34] day[#34] + (days != 1 ? [#34]s[#34] : [#34][#34]) + [#34], [#34] + hours + [#34] hour[#34] + (hours != 1 ? [#34]s[#34] : [#34][#34]) + [#34], [#34] + minutes + [#34] minute[#34] + (minutes != 1 ? [#34]s[#34] : [#34][#34]) + [#34], [#34] + seconds + [#34] second[#34] + (seconds != 1 ? [#34]s[#34] : [#34][#34]);|}|</script>|</head>||<body>|<center>|<table border=[#34]0[#34] cellpadding=[#34]1[#34] cellspacing=[#34]0[#34] id=[#34]mainbg[#34]><tr><td>||</td>|</tr>|</table>|<br>|</center>|<table border=[#34]0[#34] cellpadding=[#34]10[#34] cellspacing=[#34]0[#34]>|<tr>|<td width=[#34]500[#34] valign=[#34]top[#34] class=[#34]content[#34]>|<div align=[#34]center[#34]>|<span class=[#34]red[#34]>Days, hours, minutes, and seconds between two dates</span>|</div>||   <form id=[#34]form[#34]>|   <table cellpadding=[#34]3[#34]>|      <tr>|         <td colspan=[#34]2[#34] align=[#34]center[#34]>Enter values in <font color=[#34]#800000[#34]>mm/dd/yy hh:mm:ss</font> format</td>|      </tr>|      <tr>|         <td>First date and time</td>|         <td><input type=[#34]text[#34] name=[#34]date1[#34] /></td>|      </tr>|      <tr>|         <td>Second date and time</td>|         <td><input type=[#34]text[#34] name=[#34]date2[#34] /></td>|      </tr>|      <tr>|         <td colspan=[#34]2[#34] align=[#34]center[#34]><input type=[#34]button[#34] name=[#34]submit[#34] value=[#34]Calculate[#34] onclick=[#34]calculate(this.form)[#34] /></td>|      </tr>|      <tr>|         <td>Result</td>|         <td colspan=[#34]2[#34]><input type=[#34]text[#34] name=[#34]result[#34] readonly=[#34]readonly[#34] size=[#34]40[#34] /></td>|      </tr>|      <tr>|         <td>In (decimal) hours</td>|         <td colspan=[#34]2[#34]><input type=[#34]text[#34] name=[#34]result_h[#34] readonly=[#34]readonly[#34] /></td>|      </tr>|      <tr>|         <td>In (decimal) minutes</td>|         <td colspan=[#34]2[#34]><input type=[#34]text[#34] name=[#34]result_m[#34] readonly=[#34]readonly[#34] /></td>|      </tr>|      <tr>|         <td>In seconds</td>|         <td colspan=[#34]2[#34]><input type=[#34]text[#34] name=[#34]result_s[#34] readonly=[#34]readonly[#34] /></td>|      </tr>|   </table>||||   </form>|<script language=[#34]JavaScript[#34] type=[#34]text/javascript[#34]>|<!--|init();|//-->|</script>||</td></tr></table>|</body>|</html>"
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Times New Roman
FontSize=12
FontStyle=0
FontCharset=161
TextColor=0
TabOrder=3
ObjectType=8
Name=Text2
X=290
Y=10
W=150
H=580
Anchor=0
Font=Times New Roman
FontSize=12
FontStyle=0
FontCharset=161
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset161 Times New Roman;}}{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 ----time 1\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 [hh1] hour [mm1] min\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 [MinutesSinceMidnight1]\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 ----time 2\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 [hh2] hour [mm2] min\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 [MinutesSinceMidnight2]\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 -----minutes diff\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 [MinutesDiff]\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 -----\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 [WholeHours] HOUR  [wholeMinutes] MINUTES\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 -----\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 \par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 \par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 step1 conversion\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 min x 60 = hours\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 [decimalhour]\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 \par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 [dot] - dot location\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 decimal = [decimalmin]\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 \par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 decimal x 60 = minutes\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 converted to min = [converteddecimalmin]\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 \par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 thus\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 \par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 [hhhh] HOURS\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 and\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 [mmmm] MINUTES\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 and\par\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 [ssss] SECONDS}}}
HMargin=4
VMargin=4
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
TabOrder=4
ObjectType=3
Name=PushButton2
X=230
Y=10
W=50
H=50
Anchor=0
Text=step 1
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=Math "([hh1]*60) + [mm1]" "0" "[MinutesSinceMidnight1]"
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Times New Roman
FontSize=12
FontStyle=0
FontCharset=161
TextColor=0
TabOrder=7
ObjectType=9
Name=TextEntry1
X=60
Y=10
W=70
H=50
Anchor=0
VarName=[hh1]
Align=1
EditLen=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Times New Roman
FontSize=12
FontStyle=0
FontCharset=161
TextColor=0
TabOrder=10
ObjectType=9
Name=TextEntry2
X=140
Y=10
W=70
H=50
Anchor=0
VarName=[mm1]
Align=1
EditLen=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Times New Roman
FontSize=12
FontStyle=0
FontCharset=161
TextColor=0
TabOrder=9
ObjectType=3
Name=PushButton3
X=230
Y=70
W=50
H=50
Anchor=0
Text=step 2
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=Math "([hh2]*60) + [mm2]" "0" "[MinutesSinceMidnight2]"
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Times New Roman
FontSize=12
FontStyle=0
FontCharset=161
TextColor=0
TabOrder=5
ObjectType=9
Name=TextEntry3
X=60
Y=100
W=70
H=50
Anchor=0
VarName=[hh2]
Align=1
EditLen=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Times New Roman
FontSize=12
FontStyle=0
FontCharset=161
TextColor=0
TabOrder=8
ObjectType=9
Name=TextEntry4
X=140
Y=100
W=70
H=50
Anchor=0
VarName=[mm2]
Align=1
EditLen=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Times New Roman
FontSize=12
FontStyle=0
FontCharset=161
TextColor=0
TabOrder=6
ObjectType=3
Name=PushButton4
X=230
Y=130
W=50
H=50
Anchor=0
Text=step 3
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=If "[MinutesSinceMidnight1]" ">" "[MinutesSinceMidnight2]"¶   Math "[MinutesSinceMidnight1] - [MinutesSinceMidnight2]" "0" "[MinutesDiff]"¶Else¶   Math "[MinutesSinceMidnight2] - [MinutesSinceMidnight1]" "0" "[MinutesDiff]"¶EndIf
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Times New Roman
FontSize=12
FontStyle=0
FontCharset=161
TextColor=0
TabOrder=11
ObjectType=3
Name=PushButton5
X=230
Y=190
W=50
H=50
Anchor=0
Text=step 4
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=Math "[MinutesDiff]/60" "0" "[WholeHours]"¶Math "[MinutesDiff] - ([WholeHours]*60)" "0" "[WholeMinutes]"
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Times New Roman
FontSize=12
FontStyle=0
FontCharset=161
TextColor=0
TabOrder=12
ObjectType=3
Name=PushButton6
X=130
Y=280
W=120
H=50
Anchor=0
Text=convert step1
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=Math "[MinutesDiff]/60" "2" "[decimalhour]"
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Times New Roman
FontSize=12
FontStyle=0
FontCharset=161
TextColor=0
TabOrder=15
ObjectType=3
Name=PushButton7
X=130
Y=340
W=120
H=50
Anchor=0
Text=convert step2
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=SearchStr "." "[decimalhour]" "[dot]" ""¶StrDel "[decimalhour]" "[dot]" "3" "[hhhh]"¶DefineVar "[decimalmin]" "Decimal" "2" "Global" ""¶SubStr "[decimalhour]" "[dot]" "3" "[decimalmin]"¶Math "[decimalmin]*60" "2" "[converteddecimalmin]"
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Times New Roman
FontSize=12
FontStyle=0
FontCharset=161
TextColor=0
TabOrder=14
ObjectType=7
Name=Line1
X1=0
Y1=80
X2=220
Y2=80
EndCaps=0
LineColor=16777215
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
TabOrder=16
ObjectType=8
Name=Text4
X=0
Y=20
W=60
H=40
Anchor=0
Font=Times New Roman
FontSize=12
FontStyle=0
FontCharset=161
TextColor=16777215
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset161 Times New Roman;}}{\pard{\qc\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs24\cf0 time 1}}}
HMargin=4
VMargin=4
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=1
TabOrder=18
ObjectType=8
Name=Text5
X=0
Y=110
W=60
H=40
Anchor=0
Font=Times New Roman
FontSize=12
FontStyle=0
FontCharset=161
TextColor=16777215
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset161 Times New Roman;}}{\pard{\qc\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs24\cf0 time 2}}}
HMargin=4
VMargin=4
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=1
TabOrder=17
ObjectType=8
Name=Text6
X=10
Y=160
W=180
H=60
Anchor=0
Font=Times New Roman
FontSize=12
FontStyle=0
FontCharset=161
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset161 Times New Roman;}}{\pard{\qc\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs24\cf0 time 1 and time 2\par\qc\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs24\cf0 must be 24hr time format}}}
HMargin=4
VMargin=4
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
TabOrder=19
ObjectType=3
Name=PushButton9
X=130
Y=400
W=120
H=50
Anchor=0
Text=convert step3
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=SearchStr "." "[converteddecimalmin]" "[dot2]" ""¶StrDel "[converteddecimalmin]" "[dot2]" "3" "[mmmm]"¶¶DefineVar "[decimalsec]" "Decimal" "2" "Global" ""¶SubStr "[converteddecimalmin]" "[dot2]" "3" "[decimalsec]"¶Math "[decimalsec]*60" "2" "[ssss]"
LineColor=0
LineWidth=0
LineStyle=0
FillColor=16777215
FillPattern=0
Font=Times New Roman
FontSize=12
FontStyle=0
FontCharset=161
TextColor=0
TabOrder=13




yep.. its all correct....
only hours and minutes...

finally solved it..

now i can finally rest.. goodnight guys..
thanks to everyone who helped..
yanzco
 
Posts: 178
Joined: Sun Jul 20, 2014 4:07 am

Re: calculating time elapsed?

Postby Gaev » Wed Dec 17, 2014 8:51 am

yanzco:

but somethings wrong... i dont know where but


Oops ... messed up the calculation of WholeHours ... forgot to truncate value ... try ...
Code: Select all
Math "trunc([MinutesDiff]/60)" "0" "[WholeHours]"
Math "[MinutesDiff] - ([WholeHours]*60)" "0" "[WholeMinutes]"
User avatar
Gaev
 
Posts: 3738
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: calculating time elapsed?

Postby David de Argentina » Mon Aug 03, 2015 10:25 am

Another option:

http://specialapps.rcmediaservices.net/ ... oTimer.nbp

Has the action: ae_Elaptime

Calculates the number of seconds that have elapsed since midnight

Usage:

ae_Elaptime "ReturnVar"

ReturnVar: is the NeoBook Variable that receive the value. Don't use Brackets !!!


Example:

Code: Select all
ae_Elaptime "Initial_time"

....
...
do something
....

ae_Elaptime "final_time"

Math "[final_time]-[initial_time]" "0" "[Elaptime]"

AlertBox "Action" "The process were done in [Elaptime] seconds"



Greetings from Buenos Aires,
David de Argentina
User avatar
David de Argentina
 
Posts: 1562
Joined: Mon Apr 04, 2005 4:13 pm
Location: Buenos Aires, Argentina

Re: calculating time elapsed?

Postby virger » Tue Aug 04, 2015 12:27 pm

Quiero participar. Es simple como le enseño a mis nietos.
I want to participate. It's simple as I teach my grandchildren.

Code: Select all
{NeoBook 5 Objects}
NeoBookVer=5.80
ObjectType=8
Name=Inf
X=32
Y=3
W=214
H=30
Anchor=0
Font=Arial
FontSize=18
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\pard{\qc\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs36\cf0 Ini\tab \tab \tab Fin}}}
HMargin=0
VMargin=0
LineColor=0
LineWidth=0
LineStyle=0
FillColor=12632256
FillPattern=1
TabOrder=7
ObjectType=9
Name=EnInit
X=32
Y=31
W=105
H=30
Anchor=0
Text=07:45:00
VarName=[hi]
Align=1
EditMask=99:99:99
EditLen=8
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=18
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=6
ObjectType=9
Name=EnFin
X=141
Y=31
W=105
H=30
Anchor=0
Text=08:24:00
VarName=[hf]
Align=1
EditMask=99:99:99
EditLen=8
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=18
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=5
ObjectType=3
Name=BtExe
X=66
Y=64
W=147
H=41
Anchor=0
Text=[hh]:[mm]:[ss]
Align=2
Key=13
ImageStyle=0
ObjAction=strparse "[hi]" ":" "[ihms]" "[x]"¶strparse "[hf]" ":" "[fhms]" "[x]"¶¶if "[ihms3]" ">" "[fhms3]"¶    math "(60+[fhms3])-[ihms3]" "" "[ss]"¶    math "[fhms2]-1" "" "[fhms2]"¶else¶    math "[fhms3]-[ihms3]" "" "[ss]"¶endif¶if "[ss]" "<" "10"¶    setvar "[ss]" "0[ss]"¶endif¶¶¶if "[ihms2]" ">" "[fhms2]"¶    math "(60+[fhms2])-[ihms2]" "" "[mm]"¶    math "[fhms1]-1" "" "[fhms1]"¶else¶    math "[fhms2]-[ihms2]" "" "[mm]"¶endif¶if "[mm]" "<" "10"¶    setvar "[mm]" "0[mm]"¶endif¶¶math "[fhms1]-[ihms1]" "" "[hh]"¶if "[hh]" "<" "10"¶    setvar "[hh]" "0[hh]"¶endif
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=18
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2


Gracias por Leerme.
GdoSan/Dr.Sanchez--El Jubilado..Abril 2015
Thanks for reading me.
GdoSan / Dr.Sanchez - The Retired..April 2015
COSTA RICA
PURA VIDA
User avatar
virger
 
Posts: 524
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

PreviousNext

Return to General NeoBook Discussions

Who is online

Users browsing this forum: Bing [Bot] and 2 guests

cron