Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1332
  • Last Modified:

Subtracting 2 date fields into days, hours and minutes

I am trying to subtract two DateTime fields with the results showing how many days, hours and minutes are between the two dates. For example,

02/24/03 3:10:03 - 02/23/03 9:05:45 =

1 Day 6 hours 5 min [if I am subtracting right]

ToText(DATEDIFF('d',{TASKS.OPENDATE}, {TASKSACT.REQUESTED}))+ ' Days '
+ Totext(DatePart('h',(DateTimeValue ({TASKS.OPENDATE}-{TASKSACT.REQUESTED})) + ' Hours '))
+ Totext(DatePart('m',(DateTimeValue ({TASKS.OPENDATE}-{TASKSACT.REQUESTED})) + ' Min '))

Crystal keeps giving me an error that "A number is required here." by the ' Days ' portion, line 2 of formula. Can someone help?

Thanks, Laura
0
LRadon
Asked:
LRadon
  • 5
  • 3
1 Solution
 
mlmccCommented:
You have )'s in the wrong place

Try this

ToText(DATEDIFF('d',{TASKS.OPENDATE}, {TASKSACT.REQUESTED}))+ ' Days '
+ Totext(DatePart('h',(DateTimeValue ({TASKS.OPENDATE}-{TASKSACT.REQUESTED})))) + ' Hours '
+ Totext(DatePart('m',(DateTimeValue ({TASKS.OPENDATE}-{TASKSACT.REQUESTED})))) + ' Min '

mlmcc
0
 
LRadonAuthor Commented:
Thanks, mlmcc. I'm new to this site and am not sure exactly how the points work. I only have 75.

Your corrections spit out a reponse and the number of days is correct, however, I don't think the hour and minutes portion is calculating correctly. Here is an example:

02/03/03 11:45:24AM  02/03/03 11:46:32AM and the result was
0 Days 23.00 Hours 12.00 Min. [I don't need seconds.]

The # of days is correct, but, shouldn't the hours be 0.00 and the minutes be 1.00?

Thanks, Laura
0
 
mlmccCommented:
Yes they should.  I assume the subtraction was in the correct order (Larger - smaller)

I don't have resources here to test with so I'll look into it in the morning.

By the way what version of CR?  Are you using Crystal or Basic syntax for the formula?

mlmcc
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
mlmccCommented:
Try this

ToText(DATEDIFF('d',{TASKS.OPENDATE}, {TASKSACT.REQUESTED}))+ ' Days '
+ ToText(DATEDIFF('h',{TASKS.OPENDATE}, {TASKSACT.REQUESTED})) mod 24 +  ' Hours '
+ ToText(DATEDIFF('n',{TASKS.OPENDATE}, {TASKSACT.REQUESTED})) mod 60 +   ' Min '

in date time calculations m is for month n is for minutes

Datediff wil give you the number of PERIODS between the dates.  Using the modulus (MOD) function eliminates the full next higher period.  To get hours you must eliminate the full days

mlmcc
0
 
LRadonAuthor Commented:
Hi,

It finally took me a while to get back to this. I used the code directly above this comment and I am getting an error that says that a nummber or currency amount is required here and the cursor is always right before the "ToText" function. I played around with the formula and I deleted the "mod 24/60" parts and I didn't get that error, but now the hours and minutes are in the hundreds.

I am making progress and I bought more points. Please help me solve this.

Thanks, Laura
0
 
mlmccCommented:
Sorry missed some ( )

ToText(DATEDIFF('d',{TASKS.OPENDATE}, {TASKSACT.REQUESTED}))+ ' Days '
+ ToText((DATEDIFF('h',{TASKS.OPENDATE}, {TASKSACT.REQUESTED})) mod 24) +  ' Hours '
+ ToText((DATEDIFF('n',{TASKS.OPENDATE}, {TASKSACT.REQUESTED})) mod 60) +   ' Min '

mlmcc
0
 
LRadonAuthor Commented:
I am being fair with this grade. I finally got an answer within a half hour of posting my finally comment. Those () did the trick!!!!!!!!!!!!!!!!!Thanks, Mlmcc.

My boss was very pleased that it only cost $12.95 to solve this dilemma.


From Laura

THANK YOU!! THANK YOU!! THANK YOU!! THANK YOU!! THANK YOU!! THANK YOU!! THANK YOU!! THANK YOU!! THANK YOU!! THANK YOU!! THANK YOU!! THANK YOU!! THANK YOU!! THANK YOU!! THANK YOU!! THANK YOU!!
0
 
mlmccCommented:
No problem.  Should have seen that sooner.

Glad I could help

mlmcc
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now