Hello All,
I figured I would ask before I reinvent the wheel. Has anyone developed any functions they would want to share that calculate months and/or weeks between dates in MEL?
Thanks,
Brad
I don't have a function built, but for weeks, it is pretty easy. here is the code using DURATIONDAYS() that can translate 2 dates into weeks and days. You can put any date into the DURATIONDAYS code, including str(._TODAYSDATE) for the current day.
{tempVar = DURATIONDAYS("01/01/2016","01/27/2016")
weeks = div(tempVar,7)
days = mod(tempVar,7)
return "Weeks: " + weeks + " Days: "+ days}
You can modify the code here to check if you should put an s at the end of weeks or days, or if you don't care about the leftover days, you can only return the weeks value. Let me know if you have any questions. 🙂
Thanks! Eventually what I am going for is something like this:
Input: Date1 and Date2
Output: Between Date1 and Date2 there are x months, x weeks and x days.
Months will be the tricky part.
Oh OK. I am curious as to what kind of dates you are comparing in this way. is a general month acceptable, or does it need to exactly line up with a Calendar (consider leap year, months with different days, etc...)
Either way, the Months will be a little trickier. ^_^ Good luck!
What this is going to handle is a display for time since surgery. The providers would prefer this format over days. So date1 = date of surgery and date2 = the clinical date. I need to give them something that is accurate to the day, so I need to take into account variation in the number of days in a month and leap years.
I figured I would share a bit of what I've been working on. This part is fairly simple, but if anyone needs to figure out the number of days in a month and/or if a year is a leap year you can use the following:
(Pass the function number of the month and the year)
fn fnMonthsDays(month, year)
{
COND
CASE month == "1"
return "31"
CASE month == "2"
//determine if year is leap year.
if (fnChkLeap(year) == "true") then
return "29"
else
return "28"
endif
CASE month == "3"
return "31"
CASE month == "4"
return "30"
CASE month == "5"
return "31"
CASE month == "6"
return "30"
CASE month == "7"
return "31"
CASE month == "8"
return "31"
CASE month == "9"
return "30"
CASE month == "10"
return "31"
CASE month == "11"
return "30"
CASE month == "12"
return "31"
ENDCOND
}
fn fnChkLeap(chkYear)
{
//evenly divisable by 4, but not by 100 (except if divisable by 400)
if (mod(chkYear,4) == 0) AND ((mod(chkYear,100) <> 0) OR (mod(chkYear,400) == 0)) then
return "true"
else
return "false"
endif
}