Calculating time fields

As I crawl myself from Filemaker to Servoy :wink: , I can’t get this figured out:

For example:
fromtime = 12:30:00
untilltime = 13:15:00

In Filemaker I could do this calculation: fromtime - untilltime = 0:45:00, but how does Servoy handle this?

You have to make it a date - since there is no “time” datatype:

var startTime = new Date('1/1/2000 12:30')
var endTime = new Date('1/1/2000 13:15')

var elapsed = (endTime - startTime)/(60*1000)

60 = number of seconds in a minute
1000 = number of milliseconds in a second

Hi Karel

Keep going - the journey is worth it.

Servoy/SQL databases do work differently to FM - Maarten Berkenbosch on another thread http://forum.servoy.com/viewtopic.php?t … =calculate posted this code which I’ve found very useful:

var x = date1 - date2 //substracting two dates returns difference in milliseconds
var one_day=10006060*24 //ms * sec * min * hrs in a day

var diffExact = x / one_day //gets difference in days
var diffRounded = Math.ceil(diffExact ) // rounds 2.343 to 3

Hope this helps

Graham Greensall

Thanks fellows for your awesome input!
Also thanks to HJK who send me this code:

var newie = new Date(1970,0,1,0,0,0,0)
if(starttime && stoptime)
{
var dif = (stoptime - starttime) / (1000 * 60 * 60)
}
else
{
var dif = 0
}
if(customtime)
{
var custom = (customtime - newie) / (1000 * 60 *60) 
}
else 
{
var custom = 0
}
if(breaktime)
{
var breaking = (breaktime - newie) / (1000 * 60 * 60)
}
else
{
var breaking = 0
}
return (dif + custom) - breaking

The trick is to have a reference date and time. In this case it is 01-01-1970 0:00:00. From that point we’re able to calculate any time or date!
Hope this helpes any other person who bumps into this issue :wink:

Another way to work with dates is to use following to get yyyymmdd:

var daterequired = (required_date.getFullYear() * 10000) + (required_date.getMonth() * 100) + (required_date.getDate());

If [required_date] is 6 April 2005 this produces 20050406 which can be compared/calculated etc. Also use a Calculated Field producing yyyymm as basis for producing monthly reports.

Hope this helps

Graham Greensall
Worxinfo Ltd

high karel,

here is a link to a methode:

http://forum.servoy.com/viewtopic.php?t=3565

friedrich toussaint

friedrich toussaint:
high karel,
here is a link to a methode:
http://forum.servoy.com/viewtopic.php?t=3565
friedrich toussaint

That’s a real neat method, Friedrich! Thanks and keep up the good work!