Title

ddt -- Date/DateTime Transformations

Syntax

ddt [varelist] [, dt[(datetimevars)] dformat(dateformat) dtformat(datetimeformat) stringorder(date-elements) go ]

Description

ddt performs three related tasks in handling date/datetime data:

o- converts string to numeric

o- converts between date and datetime

o- assigns formats to final variables

Right now, all of the defaults are fixed:

o- If no varelist is specified, variables matching *date *datetime are used.

o- If dt is specified without parameters, dt(*datetime) is used.

o- If no formats are specified, df(%tdYYY-MM-DD), dtf(%tcYYYY-MM-DD HH:MM:SS), and str(YMD) are used.

Transformations use the non-leap-second-correcting functions, because otherwise the transformed display would not match the original.

ddt shows a report with 3 example rows for every selected field, showing the original and transformed values.
If the option go is not specified, it will only present this report (headed preview), and will not perform the transformations.

Options

dt[(datetimevars)] specifies variables (from those in varelist) that should hold datetime data.

dformat(dateformat) specifies the format for variables that hold date data. It is a standard Stata format string (including %).

dtformat(datetimeformat) specifies the format for variables that hold datetime data. It is a standard Stata format string (including %).

stringorder(date-elements) specifies the ordering of date elements in original string data (ie, Y, M, and D, in any order). String datetime data is assumed to be the same, followed by hms.

go specifies actually transforming the data. If go is not specified, ddt will give a preview of the results without actually changing anything.

Remarks

ddt uses the size of the original data to determine whether something is date or datetime. It could possibly be wrong in some circumstances (eg, you have datetime values, but all of them occur within twelve hours of new-years 1960).
Hopefully the preview would reveal any errors.

Examples

ddt transforms all variables ending in date or datetime to (numeric) date

ddt, dt transforms all variables ending in date to date, and all variables ending in datetime to datetime.

ddt a-e, dt(a c e) transforms variables a, c, e to datetime, and variables b and d to date.