1Time::ParseDate(3) User Contributed Perl Documentation Time::ParseDate(3)
2
3
4
6 Time::ParseDate -- date parsing both relative and absolute
7
9 use Time::ParseDate;
10 $seconds_since_jan1_1970 = parsedate("12/11/94 2pm", NO_RELATIVE => 1)
11 $seconds_since_jan1_1970 = parsedate("12/11/94 2pm", %options)
12
14 Date parsing can also use options. The options are as follows:
15
16 FUZZY -> it's okay not to parse the entire date string
17 NOW -> the "current" time for relative times (defaults to time())
18 ZONE -> local timezone (defaults to $ENV{TZ})
19 WHOLE -> the whole input string must be parsed
20 GMT -> input time is assumed to be GMT, not localtime
21 UK -> prefer UK style dates (dd/mm over mm/dd)
22 DATE_REQUIRED -> do not default the date
23 TIME_REQUIRED -> do not default the time
24 NO_RELATIVE -> input time is not relative to NOW
25 TIMEFIRST -> try parsing time before date [not default]
26 PREFER_PAST -> when year or day of week is ambigueous, assume past
27 PREFER_FUTURE -> when year or day of week is ambigueous, assume future
28 SUBSECOND -> parse fraction seconds
29 VALIDATE -> only accept normal values for HHMMSS, YYMMDD. Otherwise
30 days like -1 might give the last day of the previous month.
31
33 Absolute date formats
34 Dow, dd Mon yy
35 Dow, dd Mon yyyy
36 Dow, dd Mon
37 dd Mon yy
38 dd Mon yyyy
39 Month day{st,nd,rd,th}, year
40 Month day{st,nd,rd,th}
41 Mon dd yyyy
42 yyyy/mm/dd
43 yyyy-mm-dd (usually the best date specification syntax)
44 yyyy/mm
45 mm/dd/yy
46 mm/dd/yyyy
47 mm/yy
48 yy/mm (only if year > 12, or > 31 if UK)
49 yy/mm/dd (only if year > 12 and day < 32, or year > 31 if UK)
50 dd/mm/yy (only if UK, or an invalid mm/dd/yy or yy/mm/dd)
51 dd/mm/yyyy (only if UK, or an invalid mm/dd/yyyy)
52 dd/mm (only if UK, or an invalid mm/dd)
53
54 Relative date formats:
55 count "days"
56 count "weeks"
57 count "months"
58 count "years"
59 Dow "after next"
60 Dow "before last"
61 Dow (requires PREFER_PAST or PREFER_FUTURE)
62 "next" Dow
63 "tomorrow"
64 "today"
65 "yesterday"
66 "last" dow
67 "last week"
68 "now"
69 "now" "+" count units
70 "now" "-" count units
71 "+" count units
72 "-" count units
73 count units "ago"
74
75 Absolute time formats:
76 hh:mm:ss[.ddd]
77 hh:mm
78 hh:mm[AP]M
79 hh[AP]M
80 hhmmss[[AP]M]
81 "noon"
82 "midnight"
83
84 Relative time formats:
85 count "minutes" (count can be franctional "1.5" or "1 1/2")
86 count "seconds"
87 count "hours"
88 "+" count units
89 "+" count
90 "-" count units
91 "-" count
92 count units "ago"
93
94 Timezone formats:
95 [+-]dddd
96 GMT[+-]d+
97 [+-]dddd (TZN)
98 TZN
99
100 Special formats:
101 [ d]d/Mon/yyyy:hh:mm:ss [[+-]dddd]
102 yy/mm/dd.hh:mm
103
105 This module recognizes the above date/time formats. Usually a date
106 and a time are specified. There are numerous options for controlling
107 what is recognized and what is not.
108
109 The return code is always the time in seconds since January 1st, 1970
110 or undef if it was unable to parse the time.
111
112 If a timezone is specified it must be after the time. Year
113 specifications can be tacked onto the end of absolute times.
114
115 If "parsedate()" is called from array context, then it will return two
116 elements. On sucessful parses, it will return the seconds and what
117 remains of its input string. On unsucessful parses, it will return
118 "undef" and an error string.
119
121 $seconds = parsedate("Mon Jan 2 04:24:27 1995");
122 $seconds = parsedate("Tue Apr 4 00:22:12 PDT 1995");
123 $seconds = parsedate("04.04.95 00:22", ZONE => PDT);
124 $seconds = parsedate("Jan 1 1999 11:23:34.578", SUBSECOND => 1);
125 $seconds = parsedate("122212 950404", ZONE => PDT, TIMEFIRST => 1);
126 $seconds = parsedate("+3 secs", NOW => 796978800);
127 $seconds = parsedate("2 months", NOW => 796720932);
128 $seconds = parsedate("last Tuesday");
129 $seconds = parsedate("Sunday before last");
130
131 ($seconds, $remaining) = parsedate("today is the day");
132 ($seconds, $error) = parsedate("today is", WHOLE=>1);
133
135 David Muir Sharnoff <muir@idiom.com>.
136
138 Copyright (C) 1996-2006 David Muir Sharnoff. License hereby granted
139 for anyone to use, modify or redistribute this module at their own
140 risk. Please feed useful changes back to muir@idiom.com.
141
142
143
144perl v5.12.0 2006-08-15 Time::ParseDate(3)