A presente entrada recolle as opcións que se poden empregar no tratamento de datas con R

#strptime() to convert from character to date/time
#format() to reformat the date

format(strptime("2001-05-05", "%Y-%m-%d"), "%A %B%e, %Y")
#"Saturday May 5, 2001"

format(strptime("2001-05-05 01:05 PM", "%Y-%m-%d %I:%M %p"), "%d/%m/%Y %H:%M")
#"05/05/2001 13:05"
CodeDescription
%yYear without century (00–99). On input, values 00 to 68 are prefixed by 20 and 69 to 99 by 19
%YYear with century.
%mMonth as decimal number (01–12).
%dDay of the month as decimal number (01–31).
%eDay of the month as decimal number (1–31), with a leading space for a single-digit number.
%HHours as decimal number (00–23). As a special exception strings such as 24:00:00 are accepted for input, since ISO 8601 allows these.
%IHours as decimal number (01–12).
%MMinute as decimal number (00–59).
%REquivalent to %H:%M.
%TEquivalent to %H:%M:%S.
%pAM/PM indicator in the locale. Used in conjunction with %I and not with %H.
%aAbbreviated weekday name in the current locale on this platform. (Also matches full name on input: in some locales there are no abbreviations of names.)
%AFull weekday name in the current locale. (Also matches abbreviated name on input.)
%bAbbreviated month name in the current locale on this platform. (Also matches full name on input: in some locales there are no abbreviations of names.)
%BFull month name in the current locale. (Also matches abbreviated name on input.)
%cDate and time. Locale-specific on output, “%a %b %e %H:%M:%S %Y” on input.
%CCentury (00–99): the integer part of the year divided by 100.
%DDate format such as %m/%d/%y: ISO C99 says it should be that exact format.
%FEquivalent to %Y-%m-%d (the ISO 8601 date format).
%gThe last two digits of the week-based year (see %V). (Accepted but ignored on input.)
%GThe week-based year (see %V) as a decimal number. (Accepted but ignored on input.)
%hEquivalent to %b.
%jDay of year as decimal number (001–366).
%nNewline on output, arbitrary whitespace on input.
%rThe 12-hour clock time (using the locale’s AM or PM). Only defined in some locales.
%SSecond as decimal number (00–61), allowing for up to two leap-seconds (but POSIX-compliant implementations will ignore leap seconds).
%tTab on output, arbitrary whitespace on input.
%uWeekday as a decimal number (1–7, Monday is 1).
%UWeek of the year as decimal number (00–53) using Sunday as the first day 1 of the week (and typically with the first Sunday of the year as day 1 of week 1). The US convention.
%VWeek of the year as decimal number (01–53) as defined in ISO 8601. If the week (starting on Monday) containing 1 January has four or more days in the new year, then it is considered week 1. Otherwise, it is the last week of the previous year, and the next week is week 1. (Accepted but ignored on input.)
%wWeekday as decimal number (0–6, Sunday is 0).
%WWeek of the year as decimal number (00–53) using Monday as the first day of week (and typically with the first Monday of the year as day 1 of week 1). The UK convention.
%xDate. Locale-specific on output, “%y/%m/%d” on input.
%XTime. Locale-specific on output, “%H:%M:%S” on input.
%zSigned offset in hours and minutes from UTC, so -0800 is 8 hours behind UTC. Values up to +1400 are accepted as from R 3.1.1: previous versions only accepted up to +1200. (Standard only for output.)
%Z(Output only.) Time zone abbreviation as a character string (empty if not available). This may not be reliable when a time zone has changed abbreviations over the years.

FONTE
https://gist.github.com/zross/7fbbc034459aeff36627#file-format_dates-md

Categorías: R