How can I convert a dateformula into a duration?

DanKDanK 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

Comments

  • MBergerMBerger Member Posts: 413
    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
    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 )
  • DanKDanK Member Posts: 34
    MBerger wrote:
    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
    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 )

    Good point, I think more my purposes it is safe to assume a year is 365 and a month is 31 days.
  • MBergerMBerger Member Posts: 413
    DanK wrote:
    MBerger wrote:
    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
    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 )

    Good point, I think more my purposes it is safe to assume a year is 365 and a month is 31 days.
    Think about that carefully ( also think of future modifications ) because "Assumption is the mother of all fuckups" ;)
  • vaprogvaprog Member Posts: 1,139
    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.
  • DenSterDenSter Member Posts: 8,305
    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.
  • DanKDanK Member Posts: 34
    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,

    Dan
  • vaprogvaprog Member Posts: 1,139
    DenSter wrote:
    He doesn't want 'number of days' he wants dateformula expressed as regular words.
    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.

    On the other hand:
    DanK wrote:
    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.
    :?
  • DanKDanK Member Posts: 34
    Yeah, sorry.. my original example wasn't very clear #-o
Sign In or Register to comment.