Time Problem
vikram7_dabas
Member Posts: 611
Dear Concern
I have 1 new tabel "Attendence" in which there r 4 fields:
1). Date
2).Start Time
3).End Time
4). Total Hours worked
Suppose i m filling the attendence of today(,say Date=30/05/2009),Start Time = 10:00 P.M(Night of 30/05/09) and "End Time" = 6:00 A.M (till moarning of 31/05/09), when user fill "End Time" field,then "Total Hours worked" should come automatically.But keep in mind "Total Hours worked" should come in Date '30/05/09'.How I will do this.Plzz explain the code in Detail?
I have 1 new tabel "Attendence" in which there r 4 fields:
1). Date
2).Start Time
3).End Time
4). Total Hours worked
Suppose i m filling the attendence of today(,say Date=30/05/2009),Start Time = 10:00 P.M(Night of 30/05/09) and "End Time" = 6:00 A.M (till moarning of 31/05/09), when user fill "End Time" field,then "Total Hours worked" should come automatically.But keep in mind "Total Hours worked" should come in Date '30/05/09'.How I will do this.Plzz explain the code in Detail?
Vikram Dabas
Navision Technical Consultant
Navision Technical Consultant
0
Comments
-
Best will be to add the End Date to have Start date and End date fields to have enough details to calculate the difference (you can than create the DateTime variables for Start and End, subtract the value and you will receive the duration data type which you can recalculate to hours...).0
-
I'm wondering why you just want to display Hours Worked as a Date. In this case, you could just add an End Date field ;-)
If you really want to calculate the exact hours worked - you must also know the End Date. So like kine wrote, you should add an End Date field or you could also use DateTime as date type. In this way you should only have one field for Start Date and one for End Date.
Ex.Variable: StartDateTime : DataType DateTime EndDateTime : DateType DateTime HoursWorked : Integer
When inserting in the Attendence table:Attendence.StartDateTime := CURRENTDATETIME; Attendence.INSERT;
On the Validate Trigger for EndDateTime add:HoursWorked := (EndDateTime - StartDateTime) DIV 3600000; (EndDateTime - StartDateTime) is in milliseconds, so to get hours with have to do a division with first 1000 (=seconds), then with 60 (=minutes) and then with 60 (=hours).
So when you now add the EndDateTime, HoursWorked will be calculated automatically:Attendence.VALIDATE(EndDateTime, CURRENTDATETIME); Attendence.MODIFY(TRUE);
In case you would like to keep 2 fields per Start and End, you can still use the above example. Just change the HoursWorked calculation to the following:StartDateTime := CREATEDATETIME(StartDate, StartTime); EndDateTime := CREATEDATETIME(EndDate, EndTime); HoursWorked := (EndDateTime - StartDateTime) DIV 3600000;
0 -
Hi
You just take a Duration type variable it will give you time between StartTime to EndTime.Devendra Kr. Sharma
IBIZ Consulting Services,India0 -
Yes - Duration is also a great idea.
Just notice, that you then will have the value in the following format: "13 hours 21 minutes 55 seconds 781 milliseconds"
Depending on what you would like to use the result for - you can either use Duration or calculate HoursWorked by yourself.
My example calculates whole hours, which means that HoursWorked will be 13 and not "13 hours 21 minutes 55 seconds 781 milliseconds".
(If you like to have the decimals, then exchange DIV with / ;-) )0 -
Dear Concern
What should be the Duration Type?"Start Time" or "End Time" or "Total Hours" in Daily attendence table?Vikram Dabas
Navision Technical Consultant0 -
"Total Hours" should be Duration.
But remember, that if you choose to use duration - you must use DateTime variables to calculate the duration.
Check out Help (F1) ;-)Use this data type to represent the difference between two datetimes, in milliseconds.
This value can be negative. It is a 64 bit integer.
DATETIME-DATETIME=DURATION0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
