Normal Topic Time Formula Problem (Read 1513 times)
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Time Formula Problem
Sep 13th, 2018 at 10:18pm
Print Post Print Post  
Hey folks,

I'm working on a formula to let people in our company manage vacation time, flex time, etc.  I've built the following code below, and it works to a degree -- if I put in '8:58' in for a start time instead of '8:30', it tells me that I've used 0.5 flex hours.  However, if I put '8:00' I don't get -0.5 (which I want), I get 16.5 hours, and no idea how this is happening or how to fix it.

Help?


Code
Select All
var vButtonOn as int
var vOK as int

var vDate as date = @serverdate()
var vStart as time
var vEnd as time
var vFlex as double
var vFlexTotal as double
var vAbsTotal as double
var vVacTotal as double
var vStaffStats as string

var vTest as double

notifyform(0)

vStaffStats = @xlookupsourcelist(@FN, @userid, "Staff Screen!StaffRef","StAbsCt;StPrsCt;StVacCt")

// 2011-01-11 BW ADDED SECURITY - USERS CAN'T ACCESS STAFF SCREEN

if @group <> "Users" then vOK = 0
if @userid = "BW" then vOK = 1

if @Xlookupsourcelist(@FN, @userid, "Staff Screen!StaffRef", "StAccFlex") = 1 then vOK = 1

if vOK = 1
{
	vFlexTotal = @accessstringarray(vStaffStats,2)

	vDate = @promptforuserinput("Flex Date?",vDate)
	vStart = @promptforuserinput("Start Time?", "8:30:00")
	vEnd = @promptforuserinput("End Time?", "17:00:00")

	vFlex = @totime(vStart) - @totime("8:30:00")

	vFlex = @round((vFlex/15),0) * 15 / 60

Writeln("You are using " + vFlex + " of your accumulated " + vFlexTotal + " time")
}

ELSE
{
	@MsgBox("","You Don't Have Access to This Function","")
}

 

  
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Time Formula Problem
Reply #1 - Sep 14th, 2018 at 1:34pm
Print Post Print Post  
Hi Blair,

Think of Time variables as a 24 hour clock. If it's currently 07:00, and you go back 8 hours in time, you end up at 23:00.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Re: Time Formula Problem
Reply #2 - Sep 14th, 2018 at 3:22pm
Print Post Print Post  
Hi Ray,

That makes sense, but wouldn't inputting in my code above with a start time of 9:00 instead of 8:30 shouldn't I get a result of 23.5 instead of 16.5?  I'm not sure how that math works.

Alternatively, is there an easy way to figure out the difference from vStart and 8:30 from midnight in minutes, and then calculate the difference?  That might be easier?
  
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Time Formula Problem
Reply #3 - Sep 14th, 2018 at 4:11pm
Print Post Print Post  
Running your code here I get 23.5 if I input "8:00" and 15.75 if I input simply "8". as that is 00:08 - 8:30.

If you use @ToNumber() on your time values you will get the result in minutes. Store those in Int variables and you can then perform whatever math you want on those values.
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Re: Time Formula Problem
Reply #4 - Sep 14th, 2018 at 9:44pm
Print Post Print Post  
@ToNumber worked great … thanks!
  
Back to top
IP Logged