Hi, I get via a data-import for instance the following dates: 10-11-2001 02-04-2000 06-07-1999 02-08-2000. The year of these dates has to be changed in 2002. Can this be done by using CALCDATE and just one date expression?
DateVar := 10112000D; NewDate := DMY2DATE(DATE2DMY(DateVar,1),DATE2DMY(DateVar,2),2001); (=10-11-2001)
Okay Anfinnur, I know, but can it be done by just using CALCDATE?
quote:
Originally posted by Anfinnur
DateVar := 10112000D; NewDate := DMY2DATE(DATE2DMY(DateVar,1),DATE2DMY(DateVar,2),2001); (=10-11-2001)
It can be done using the following code: newDate := CALCDATE(’+CY+’ + FORMAT(ROUND((311202D-CALCDATE(’+CY’,oldDate))/365.25,1)) + ‘Y-’ + FORMAT(CALCDATE(’+CY’,oldDate)-oldDate) + ‘D’, oldDate); Although I think it is bad practice to use code like this that will inevitably give the next programmer to maintain the code a nosebleed. It is better to write the above in distinct steps so it is easy to follow (unless performance is the overriding issue). (Note: prior to use the above code will need to be tinkered with to handle leap years - probably by using months rather than years).