How to calculate and reformat dates
HelpFile Links : GetDate | DateAdd | DatePart | MidStr | If | Let | MessageModal
A frequent requirement is that of adding days to a date - usually today's date - and then reformatting the outcome to a specific format.
This can be done with the built in date functions which allow you to add or subtract days, months or years to a date and break dates apart into their component parts.
Here's an example which gets today's date, adds 5 days to it and then reformats the outcome with DDMMYY format.
//get today's date GetDate>today //Add 5 days to it DateAdd>today,D,5,new_date //get the bits DatePart>new_date,D,day_part DatePart>new_date,M,month_part DatePart>new_date,Y,year_part //year_part is 4 digits, so we want only last 2 MidStr>year_part,3,2,year_bits //Make sure we prepend with zeros if day is only 1 char If>{length("%day_part%") < 2} Let>day_part=0%day_part% Endif //Make sure we prepend with zeros if month is only 1 char If>{length("%month_part%") < 2} Let>month_part=0%month_part% Endif //now put them together in the format you want (DDMMYY) Let>formatted_date=%day_part%%month_part%%year_bits% MessageModal>formatted_date
See the help file for details on these functions. DateAdd can take months or years instead of days and can also be used to subtract from the date. Similar functions exist for times. Use the DateDiff function to determine the difference between dates, in days, months or years.