How to format 2 number yy values to 4 number yyy values in datetimes (19XX - 20XX)?

0
Hi Business Engineers,   I am formatting date time with 2 numbers for years (yy) to 4 numbers (yyyy). When all the date times are of the 20th century, i add 1900 years, and I get a correct 4 numbers yyyy. But when the original date times are also from 21ths century ('17) how should I divide to add 1900 years or 2000 years in orde to complete '70 to 1970 or '17 to 2017?   This solution worked for me: if $DataImport/DateTime !=empty and parseInteger(formatDateTimeUTC(trimToYearsUTC(parseDateTimeUTC($DataImport/DateTime,'dd/MM/yyyy')), 'yyyy'))<= 40 then addYearsUTC(parseDateTimeUTC($DataImport/DateTime,'dd/MM/yyyy'), 2000) else if $IteratorParticulier/geboortedatum !=empty and parseInteger(formatDateTimeUTC(trimToYearsUTC(parseDateTimeUTC($DataImport/DateTime,'dd/MM/yyyy')), 'yyyy'))> 40 then addYearsUTC(parseDateTimeUTC($DataImport/DateTime,'dd/MM/yyyy'), 1900) else empty  
asked
2 answers
3

Enzo,

If you use the built in Mendix function FormatDateTime, you can perform this without having to add anything to the date.  Formatting options for this function can be found here:  http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

Hope that helps,

Mike

answered
1

You either have to build some logic yourself (''Numbers lower than 30 add 2000, numbers higher than 30 add 1900" or something similar). 

It's impossible to deduce which year a double digit year stands from without providing it

answered