Link to home
Start Free TrialLog in
Avatar of trailblazzyr55
trailblazzyr55

asked on

Date/Time Math

I have an app dealing with Time differences that I'm trying create. Here's what I'm looking to do

Variables: Time1, Time2, Time3, NumberOfHrs

What I want is to subtract the Time2 from Time1 for a given number of hours.
Then subtract that number of hours/mins from NumberOfHours.
Then add that number of hours to Time3 to get a final time.

Math would look like this... NumberOfHours is 8

(8 - #DateDiff("n", Time1, Time2)#) + Time3 = FinalTime

This is just an example, but I can't seem to get the date functions correct, would anyone have an idea how to go about this...?
Variables are set by form fields in two parts so time1 would consist of two form fields Time1hrs & Time1mins equaling Time1.

The idea behind this is for a timeclock, so you clock in at a certain time, clock out for break, clock in from break, then you know what time you have to clock out for based on a set number of hours work day, I used 8 in this example.

Example:

Clock in: 8:30AM        \
Lunch:   11:30AM         \_____________Given variables
Return:  12:15PM         /
                                /
8 Hour day:             /

Must Clock out at: 5:45PM    <------ show time to clock out

What's the best way to perform this date/time math with CF?

 



ASKER CERTIFIED SOLUTION
Avatar of pinaldave
pinaldave
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I guess the the code of enTrance is following the same logic I proposed before :)
Ooopppsss...!  By the way, just a correction on the mask for displaying the time.

Use this : #TimeFormat(FinalTime,'h:mmtt')#


Regards!
eNTRANCE2002 :-)
Hmmmmm ... :-?

Pinaldave, I think it's different from your logic.  And by the way, 8*60 is 480.

Here's the flow on how did I get the Final time :
1.  Get the total no. of mins from Clock In to Lunch.
2.  Considering the expected no. of mins (8*60), it will be subtracted by the result on #1.
3.  The result on #2 will be added on Return.

Hope this is clear to you.


Regards!
eNTRANCE2002 :-)

Hi trailblazzyr55!

How is it going right now ???  May we know what's the status of your problem ?


Regards!
eNTRANCE2002 :-)
Avatar of Jerry_Pang
Jerry_Pang

Example:

Clock in: 8:30AM        \
Lunch:   11:30AM         \_____________Given variables
Return:  12:15PM         /
                                /
8 Hour day:             /

given time1, time2 time3
time1 2 and 3 formats is only HH and MM textboxes.

>>What's the best way to perform this date/time math with CF?

1 way is compute in terms of minutes - round off to minutes then do the math.

Timein
8x60 + 30 = 510
11x60 +30 = 690
---------------------
180mins = 3hrs

480 - 180 = 300mins left

2nd Timein
12x60 + 15 = 735
----------------------
time out is 735 + 300(mins left) = 1035
1035 round off = div 60 and mod 60 to 24h
1035/60 = 17.sumthing  (hrs)
1035 mod 60 = 15  (mins)
17hrs 15mins
time out  at 1715h = 5:15

This does not work IF timeout is next day or if the timein was yesterday. does not work with night shifts.
If this is an issue, you need the DATES! you need to convert those textboxes to dateformats.

another way, what they have suggested.
convert those 2 textboxes hhmm to timeformat first then use your formula.

Avatar of trailblazzyr55

ASKER

entrance2002, pinaldave,

Thanks for giving me some ideas! I got it working perfect now and have added and an ***load of error checking and messages, basically just a fun project and seeing what I can do with it. One thing though, both your answers are very similar. I want to be fair and have the points go where they are deserved. I've got ideas from both your comments and haven't used either as posted exactly. So what you you two think about points?

To me if someone answered someones question, great.. I'm not competing for points really, it's fun but nothing to get hard feelings over. If I did have hard feelings on here, I'd have it out with mrichmon! he always one ups me on questions :o)!! lol, all in good fun though!

Anyway.. wanted to see what you's thought was fair, if its not really a big deal to both of you then I'll split the points.

Jerry_Pang,
 Thanks for your post, by the time you posted I'd already found a solution, but I always think it's great to find more than one way of doing something and thank you for your comment.

Thanks all....

Best Regards,
~trail
split is perfect. :)
Thanks for your comment. It is always fun to read interesting problems and explaination to answers.
Regards,
---Pinal
Hi trailblazzyr55!

I'm glad that you got an idea from my comment.  Hope to help you again ...

By the way, I agree with pinaldave.  Splitting the points would be fair.


Regards!
eNTRANCE2002 :-)
Ok seems fair enough, split it is... thank you both for your comments.

Also jerry thanks for your input as well!

Best Regards,
~trail