How can I convert a dateformula into a duration?
                
                    DanK                
                
                    Member Posts: 34                
            
                        
            
                    Hi guys,
I have a series of dateformula fields that I want to convert into durations. Is this possible?
e.g. I need '1Y' to be expressed as a duration of one year, 1M one month... etc
Thanks
Dan
                I have a series of dateformula fields that I want to convert into durations. Is this possible?
e.g. I need '1Y' to be expressed as a duration of one year, 1M one month... etc
Thanks
Dan
0                
            Comments
- 
            
I wouldn't do that...there is no distinct duration of a month : it can be 28, 29,30 or 31 days. Same goes for a year ( 365 or 366 )DanK wrote:Hi guys,
I have a series of dateformula fields that I want to convert into durations. Is this possible?
e.g. I need '1Y' to be expressed as a duration of one year, 1M one month... etc
Thanks
Dan0 - 
            MBerger wrote:
I wouldn't do that...there is no distinct duration of a month : it can be 28, 29,30 or 31 days. Same goes for a year ( 365 or 366 )DanK wrote:Hi guys,
I have a series of dateformula fields that I want to convert into durations. Is this possible?
e.g. I need '1Y' to be expressed as a duration of one year, 1M one month... etc
Thanks
Dan
Good point, I think more my purposes it is safe to assume a year is 365 and a month is 31 days.0 - 
            
Think about that carefully ( also think of future modifications ) because "Assumption is the mother of all fuckups"DanK wrote:MBerger wrote:
I wouldn't do that...there is no distinct duration of a month : it can be 28, 29,30 or 31 days. Same goes for a year ( 365 or 366 )DanK wrote:Hi guys,
I have a series of dateformula fields that I want to convert into durations. Is this possible?
e.g. I need '1Y' to be expressed as a duration of one year, 1M one month... etc
Thanks
Dan
Good point, I think more my purposes it is safe to assume a year is 365 and a month is 31 days.
                        0 - 
            What you intend to do can be likened to the attempt to store the result of an integer division in an integer. The result may be good, but it is more likely that it is not exact, and the error might range between neglectable to unacceptable.
The easiest way to get a duration in days is to apply the formula to just any date (somewhere in the middle of the range of valid dates), subtract the original date from the result and assign this difference to an integer.0 - 
            He doesn't want 'number of days' he wants dateformula expressed as regular words.
You'll have to write your own functions to convert that. If you want an example of a structure find the check report, that has functions that translate numbers into words, so you can kind of use that as inspiration of how to program that.0 - 
            vaprog wrote:What you intend to do can be likened to the attempt to store the result of an integer division in an integer. The result may be good, but it is more likely that it is not exact, and the error might range between neglectable to unacceptable.
The easiest way to get a duration in days is to apply the formula to just any date (somewhere in the middle of the range of valid dates), subtract the original date from the result and assign this difference to an integer.
^ This is exactly what I ended up doing. I needed to compare a duration field with a dateformula field.. hense the need to convert the dateformula into the appropriate type.
My code ended up like this:
duration := (CALCDATE(dateformula,WORKDATE) - WORKDATE);
If anyone can suggest a better way of doing this I'd love to hear it.
Thanks,
Dan0 - 
            
Oh, you're right. I read that but did not get it's meaning, so I ignored it. Now you told me, this explanatory remark in the original request makes sense.DenSter wrote:He doesn't want 'number of days' he wants dateformula expressed as regular words.
On the other hand:
:?DanK wrote:
^ This is exactly what I ended up doing.The easiest way to get a duration in days is to apply the formula to just any date (somewhere in the middle of the range of valid dates), subtract the original date from the result and assign this difference to an integer.0 - 
            Yeah, sorry.. my original example wasn't very clear #-o0
 
Categories
- All Categories
 - 73 General
 - 73 Announcements
 - 66.7K Microsoft Dynamics NAV
 - 18.7K 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
 - 617 NAV Courses, Exams & Certification
 - 2K Microsoft Dynamics-Other
 - 1.5K Dynamics AX
 - 323 Dynamics CRM
 - 111 Dynamics GP
 - 10 Dynamics SL
 - 1.5K Other
 - 990 SQL General
 - 383 SQL Performance
 - 34 SQL Tips & Tricks
 - 35 Design Patterns (General & Best Practices)
 - 1 Architectural Patterns
 - 10 Design Patterns
 - 5 Implementation Patterns
 - 53 3rd Party Products, Services & Events
 - 1.6K General
 - 1.1K General Chat
 - 1.6K Website
 - 83 Testing
 - 1.2K Download section
 - 23 How Tos section
 - 252 Feedback
 - 12 NAV TechDays 2013 Sessions
 - 13 NAV TechDays 2012 Sessions
 

