Learn R Programming

TimeWarp (version 1.0.15)

dateFormat: Converts a Date object to character data

Description

Converts a Date object to character data

Usage

dateFormat(date, format = NULL, optimize.dups=TRUE)

Arguments

date

A vector of dates. Can be character data or some date object -- anything that can be handled by dateParse()

format

A specification of the format. The default will print as "YYYY-MM-DD" under both Windows and Linux.

optimize.dups

If TRUE, internally optimize by not performing the same computation multiple times for duplicates. This does not change the return value.

Value

The formatted dates as a vector of character data.

Details

Unfortunately, 'format.POSIXct' does not have the same behavior on Linux and Windows. Here are a few for the difference found in 2008:

  1. Windows version does not recognize "%y" format.

  2. Windows version does not recognize width arguments like "%02d".

  3. Windows and Linux does not agree on the meaning of "%Y". Under Windows it means "%04Y"; under Linux it prints with minimal width.

This function tries to provide identical behavior under Linux and Windows and Mac. This function formats any kind of data objects to character strings with the default format "%04Y-%02m-%02d" under both Linux and Windows. It does this by choosing a system-specific default format and then calling format().

Additional format specifications are also provided:

  • '%Q' for quarter, as 'Q1', etc (the value returned by quarters()

  • '%C' for century, always 2 digits (e.g., '20' for 2013)

Examples

Run this code
# NOT RUN {
dateFormat(as.Date('2001-02-13'), '%Y.%02m.%02d')
# }

Run the code above in your browser using DataLab