---
title: "Dates and times"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Dates and times}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

## Formats

There are three common formats across SAS, SPSS and Stata.

Date (number of days)

* SAS:    MMDDYY, DDMMYY, YYMMDD, DATE
* Spss:   n/a
* Stata:  %td

Time (number of seconds):

* SAS:   TIME, HHMM, TOD 
* Spss:  TIME, DTIME
* Stata: n/a

DateTime (number of seconds):

* SAS:   DATETIME
* Spss:  DATE, ADATE, SDATE, DATETIME (as milliseconds)
* Stata: %tc, %tC


## Offsets

Dates and date times use a difference offset to R:

* SAS: 1960-01-01 (`r -as.integer(as.Date("1960-01-01"))` days)
* Spss: 1582-10-14. (`r -as.integer(as.Date("1582-10-14"))` days)
* Stata: 1960-01-01. (`r -as.integer(as.Date("1960-01-01"))` days)


## References

* SAS: 
  <https://v8doc.sas.com/sashtml/lrcon/zenid-63.htm>,
  <http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/viewer.htm>
  
* Spss:
  <http://www-01.ibm.com/support/knowledgecenter/#!/SSLVMB_20.0.0/com.ibm.spss.statistics.help/idh_idd_dtwz_learn.htm>
  <http://www-01.ibm.com/support/knowledgecenter/#!/SSLVMB_20.0.0/com.ibm.spss.statistics.help/syn_date_and_time_date_time_formats.htm>

* Stata:
  <https://www.stata.com/manuals13/u24.pdf>
