LRadon
asked on
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',(DateT imeValue ({TASKS.OPENDATE}-{TASKSAC T.REQUESTE D})) + ' Hours '))
+ Totext(DatePart('m',(DateT imeValue ({TASKS.OPENDATE}-{TASKSAC T.REQUESTE D})) + ' 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
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
+ Totext(DatePart('h',(DateT
+ Totext(DatePart('m',(DateT
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
ASKER
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
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
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
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
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
ToText(DATEDIFF('d',{TASKS
+ ToText(DATEDIFF('h',{TASKS
+ ToText(DATEDIFF('n',{TASKS
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
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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!!!!!!!!!!!!!!!!!Than ks, 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!!
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!!
No problem. Should have seen that sooner.
Glad I could help
mlmcc
Glad I could help
mlmcc
Try this
ToText(DATEDIFF('d',{TASKS
+ Totext(DatePart('h',(DateT
+ Totext(DatePart('m',(DateT
mlmcc