Parsing and Formatting Dates
In PAW, you can either use the "Text to Columns" functionality for simple data parsing or "Add calculated fields" for more complex processing. We've put reference material for some common parsing requirements.
Date Parsing
PAW uses the standard notation for specifying date formats used in Java/Groovy. Below are the patterns for the different date and time components, and some examples of formats for use in "Text to columns" and scripting.Formats for Date and Time Components
| Letter | Date or Time Component | Example Usages | Results |
| G | Era designator | G | AD |
| y | Year | yyyy yy |
1996 96 |
| M | Month in year | MMMMM MMM MM |
July Jul 07 |
| w | Week in year | w | 27 |
| W | Week in month | W | 2 |
| D | Day in year | D | 189 |
| d | Day in month | d dd |
8 08 |
| F | Day of week in month | F | 2 |
| E | Day in week | EEEE EEE |
Tuesday Tue |
| a | Am/pm marker | a | PM |
| H | Hour in day (0-23) | H HH |
0 00 |
| k | Hour in day (1-24) | k | 24 |
| K | Hour in am/pm (0-11) | K | 0 |
| h | Hour in am/pm (1-12) | h hh |
5 05 |
| m | Minute in hour | m mm |
30 30 |
| s | Second in minute | s ss |
5 05 |
| S | Millisecond | SSS | 978 |
| z | Timezone | z | Pacific Standard Time; PST; GMT-08:00 |
| Z | Timezone | Z | -0800 |
Examples
Below are examples of typically displayed date formats from different programs.| Pattern | Result |
| "yyyy.MM.dd G 'at' HH:mm:ss z" | 2001.07.04 AD at 12:08:56 PDT |
| "EEE, MMM d, ''yy" | Wed, Jul 4, '01 |
| "h:mm a" | 12:08 PM |
| "hh 'o''clock' a, zzzz" | 12 o'clock PM, Pacific Daylight Time |
| "K:mm a, z" | 0:08 PM, PDT |
| "yyyyy.MMMMM.dd GGG hh:mm aaa" | 02001.July.04 AD 12:08 PM |
| "EEE, d MMM yyyy HH:mm:ss Z" | Wed, 4 Jul 2001 12:08:56 -0700 |
| "yyMMddHHmmssZ" | 010704120856-0700 |
| "yyyy-MM-dd'T'HH:mm:ss.SSSZ" | 2001-07-04T12:08:56.235-0700 |
Scripting Example
Scripting through calculated fields allows the user to do much more in terms of being able to manipulate information. This includes parsing data as well as formatting it.Parsing a date from text
dateText = "Fri Jan 11 08:15:10 PDT 2008"
df = new java.text.SimpleDateFormat("EEE MMM d HH:mm:ss z yyyy")
parsedDate = df.parse(dateText)
Formatting a date value to text for output
df = new java.text.SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss")
dateText = df.format(dateValue)
Value of dateText: Fri, 11 Jan 2008 08:15:10
Additional references
These articles on the web may change over-time and we cannot guarantee the continued accuracy of the information, but contain good additional tips.- Handling dates in Groovy - http://pleac.sourceforge.net/pleac_groovy/datesandtimes.html
- Java date formatting - http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html
