Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subtract two datetime field

Status
Not open for further replies.

tumap

Technical User
Aug 14, 2001
4
US
Help

I have two datetime field, and I need to know the duration between the days (how long does it take). My two datetime field are {open.time} and {close.time}. I am trying to subtract {close.time}-{open.time} . But the result is day, but I want how many hour does it take? I convert the fields to seconds with the knowledbase on Crystal website, but it gave me wrong result. I think the problem is that Crystal report does not take days in when it calculate the field. So, can anyone help me please? Thanks in advance.
 
Hi,

The following formula will give you days,hours,mins ...

local numbervar a := datetime2 - datetime1;
local numbervar b := truncate(a);
local numbervar c := (a - b)*24;
local numbervar d := truncate(c);
local numbervar e := (c - d)*60;
totext(b,"#")+" days, " + totext(c,"#") +" hours, " + totext(e,"#")+" mins"

Hth,
Geoff
 
The difference in hours between two datetimes:
DateDiff('h', {open.time}, {close.time})
Or use 'n' for minutes (not 'm', which gives you months), or 's' for seconds.
 
First, make sure that this field is being read as a date-time field. CR hss an option to convert DateTime fields to Dates automatically.

Also, are you trying to do Calendar hours or Business hours? IF you are using Business hours see my FAQ on common formulas. It will show you how to do Business Dates and will give you some help on business hours. Ken Hamady, On-site/Phone Crystal Reports Training/Consulting
Quick Reference Guide to using Crystal in VB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top