DATEFMT

The DATEFMT function converts a date or timestamp from one format to another.

The input for DATEFMT can be a character field, a date or timestamp, or a packed decimal number.


1  DATEFMT ( Input_String, Output_Format, Input_Format )  DATEFMT ( Input_String, Output_Format, Input_Format )
  • Input string - The string to be converted.
  • Output format - A format pattern for the output date.
  • Input format - A format pattern for the input date.

The format pattern consists of a date portion optionally followed by a time portion. If the time portion is not present, a date will be returned, otherwise a timestamp will be returned. If the input is a packed decimal field, it will be unpacked before matching the pattern.

  • TOD - A double word that is compatible with the the output of a STCK instruction
  • DD - Two digit day of month
  • DDD - Three digit day of year
  • MM - Two digit month
  • MMM - Three character month name.
  • YY - Two digit year
  • YYYY - Four digit year
  • HH - Two digit hour
  • MM - Two digit minute
  • SS - Two digit seconds
  • HSEC - Two digit seconds/100
  • MSEC - Six digit microseconds
Valid pattern strings for the date are:
DD MMM YYYY
YYYY-MM-DD
YYYY/MM/DD
YYYY.MM.DD
YYYYMMDD
YY-MM-DD
YY/MM/DD
YY.MM.DD
YYMMDD
MM-DD-YYYY
MM/DD/YYYY
MM.DD.YYYY
MMDDYYYY
MM-DD-YY
MM/DD/YY
MM.DD.YY
MMDDYY
DD-MM-YYYY
DD/MM/YYYY
DD.MM.YYYY
DDMMYYYY
DD-MM-YY
DD/MM/YY
DD.MM.YY
DDMMYY
YYYY-DDD
YYYY/DDD
YYYY.DDD
YYYYDDD
YY-DDD
YY/DDD
YY.DDD
YYDDD
Valid pattern strings for the time are:
HH:MM:SS
HH:MM:SS.HSEC
HH:MM:SS:MSEC
HHMMSSHSEC
HHMMSSMSEC
HH.MM.SS
HH.MM.SS.HSEC
HH.MM.SS:MSEC

Example

SELECT DATEFMT(01033,'YYYY-MM-DD','YYDDD') returns the value 2001-02-02.