Date data types are incredibly powerful and flexible, but figuring out how to use them to do date format conversions...
can be frustrating because the examples in the manuals never seem to get to the meat of the issue and give you simple examples. The key to understanding how to do the conversions is to realize that the date data-type field is in ALL formats. You can put any date format into it and pull any date format out of it. Here are some real-world examples:
First define a work field as a date data type
D WorkDate s d
Use the work field as your conversion method by putting a date in one format into it and pulling out that date in another format. To convert *MDY to *ISO
C *MDY Move MDYDate WorkDate C *ISO Move WorkDate ISODate *USA to *MDY C *USA Move USADate WorkDate C *MDY Move WorkDate MDYDate
Note that the work field doesn't need a date format defined, it's ALL formats. The formatting is required to tell what date format is going into the work field (first line) and what format you want to come out (second line). The data being moved into the work field must be a valid date in the format you specified or the program will crash, so it's a good idea to test the validity first.
C *USA TestD USADate 70
*IN70 will be turned on if the date is not a valid date in *USA (MMDDYYYY) format.
You can even do date conversions from/to character fields to/from numeric fields, but remember that the character field must include the separators ('02/05/01') going into the conversion and be long enough to hold the separators coming out of the conversion.