One of the most frustrating things I had to do while working as financial business analysts was working with Data Time Formats in Base SAS. The syntax was simple enough and SAS was quite good with handing queries to the Oracle data base that the client was using, but remembering the different types of formats in SAS language was a challenge (there was a date9. and date6 and mmddyy etc )
Data and Time variables are particularly important variables in financial industry as almost everything is derived variable from the time (which varies) while other inputs are mostly constants. This includes interest as well as late fees and finance fees.
In R, date and time are handled quite simply-
Use the strptime( dataset, format) function to convert the character into string
For example if the variable dob is “01/04/1977) then following will convert into a date object
and if the same date is 01Apr1977
does the same
For troubleshooting help with date and time, remember to enclose the formats
%d,%b,%m and % Y in the same exact order as the original string- and if there are any delimiters like ” -” or “/” then these delimiters are entered in exactly the same order in the format statement of the strptime
Sys.time() gives you the current date-time while the function difftime(time1,time2) gives you the time intervals( say if you have two columns as date-time variables)
What are the various formats for inputs in date time?
- Abbreviated weekday name in the current locale. (Also matches full name on input.)
- Full weekday name in the current locale. (Also matches abbreviated name on input.)
- Abbreviated month name in the current locale. (Also matches full name on input.)
- Full month name in the current locale. (Also matches abbreviated name on input.)
- Date and time. Locale-specific on output,
"%a %b %e %H:%M:%S %Y"on input.
- Day of the month as decimal number (01–31).
- Hours as decimal number (00–23).
- Hours as decimal number (01–12).
- Day of year as decimal number (001–366).
- Month as decimal number (01–12).
- Minute as decimal number (00–59).
- AM/PM indicator in the locale. Used in conjunction with
%Iand not with
%H. An empty string in some locales.
- Second as decimal number (00–61), allowing for up to two leap-seconds (but POSIX-compliant implementations will ignore leap seconds).
- Week 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.
- Weekday as decimal number (0–6, Sunday is 0).
- Week 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.
- Date. Locale-specific on output,
- Time. Locale-specific on output,
- Year without century (00–99). Values 00 to 68 are prefixed by 20 and 69 to 99 by 19 – that is the behaviour specified by the 2004 POSIX standard, but it does also say ‘it is expected that in a future version the default century inferred from a 2-digit year will change’.
- Year with century.
- Signed offset in hours and minutes from UTC, so
-0800is 8 hours behind UTC.
- (output only.) Time zone as a character string (empty if not available).
- Also to read the helpful documentation (especially for time zone level, and leap year seconds and differences)
- Mark-up Your Events Online with Microformats (seomoz.org)
- How do you convert octal numbers to decimal numbers (wiki.answers.com)
- The Rollover of Doom: a Trap for Good Programmers (esr.ibiblio.org)
- Formatting Dates, Times and Numbers in ASP.NET (4guysfromrolla.com)
- Rcpp 0.9.0 and RcppClassic 0.9.0 (dirk.eddelbuettel.com)
- Comparing times and dates in Ruby (nofluffjuststuff.com)
- C#: Programatically Convert between ASCII, Decimal, and Hexidecimal (lockergnome.com)
- Scale and Scalability: Rethinking the Most Overused IT System Selling Point for the Cloud Era (itexpertvoice.com)
- Coding Horror: A Visual Explanation of SQL Joins (codinghorror.com)