DTOC(datefield)
This will return a caracter value for the date in the form MM/DD/YY. The exact format of the date will be dependant on your settings for SET DATEand
SET CENTURYIf as an alternative, you use
DTOC(datefield,1)The date will always be returned as an 8 character string in the form
YYYYMMDDThis field is not very pretty for display purposes, and I would not use it for that purpose, but it is excellent if you need to create a character string that includes the date along with other character data.
DTOC(datefield,1)One of 2 things happen to me, I either miss the ,1 and read it as
DTOC(datefield)
Or I open my help file to figure out what the ,1 does. Either way, this is not clear and clean code. If I need an 8 character, sortable date in a string format, I would use insteadDTOS(datefield)
This would return my 8 character YMD string regardless of the settings for Set Dateand
Set CenturyWe are good so far, but now we run into a problem with consistency with time commands. The following commands are valid
TTOC(DateTimeField) TTOC(DateTimeField,1)But, there is no command for
TTOS(DateTimeField)Thus, while we could use DTOS, there is no corresponding TTOS. My solution here would be to create a new function as follows
Function TTOS(DateTimeField) Return TTOC(DateTimeField,1)By using my TTOS instead of the built in TTOC(DateTimeField,1) function, I mirror the DTOS function for clarity and consistency, while hiding the ,1 parameter from day to day use.
DTOC(DateField)
becomesFunction DateToCharacter(DateField) return DTOC(DateField)
DTOS(DateField)
becomesFunction DateToString(DateField) return DTOS(DateField)With the expanded names, the purpose of the functions becomes more clear, and the code becomes more easily readable and maintanable. Any parameters are moved down the code tree, where they can be ignored on a day to day basis.