blob: 5af9f8c732a284c4a0689027402550b0492461fa [file] [log] [blame]
adminb0dd10f2006-08-25 17:25:49 +00001<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html>
3<head>
4
5<title>Code Igniter User Guide</title>
6
7<style type='text/css' media='all'>@import url('../userguide.css');</style>
8<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
9
10<script type="text/javascript" src="../scripts/nav.js"></script>
11<script type="text/javascript" src="../scripts/prototype.lite.js"></script>
12<script type="text/javascript" src="../scripts/moo.fx.js"></script>
13<script type="text/javascript">
14window.onload = function() {
15 myHeight = new fx.Height('nav', {duration: 400});
16 myHeight.hide();
17}
18</script>
19
20<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
21<meta http-equiv='expires' content='-1' />
22<meta http-equiv= 'pragma' content='no-cache' />
23<meta name='robots' content='all' />
24<meta name='author' content='Rick Ellis' />
25<meta name='description' content='Code Igniter User Guide' />
26
27</head>
28<body>
29
30<!-- START NAVIGATION -->
31<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
32<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle.jpg" width="153" height="44" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
33<div id="masthead">
34<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
35<tr>
admin9fc347d2006-09-21 00:00:28 +000036<td><h1>Code Igniter User Guide Version 1.4.1</h1></td>
adminb0dd10f2006-08-25 17:25:49 +000037<td id="breadcrumb_right"><a href="../toc.html">Full Table of Contents</a></td>
38</tr>
39</table>
40</div>
41<!-- END NAVIGATION -->
42
43
44<!-- START BREADCRUMB -->
45<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
46<tr>
47<td id="breadcrumb">
48<a href="http://www.codeigniter.com/">Code Igniter Home</a> &nbsp;&#8250;&nbsp;
49<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
50Directory Helper
51</td>
52<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="www.codeigniter.com/user_guide/" />Search User Guide&nbsp; <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />&nbsp;<input type="submit" class="submit" name="sa" value="Go" /></form></td>
53</tr>
54</table>
55<!-- END BREADCRUMB -->
56
57<br clear="all" />
58
59
60<!-- START CONTENT -->
61<div id="content">
62
63
64<h1>Date Helper</h1>
65
66<p>The Date Helper file contains functions that help you work with dates.</p>
67
68
69<h2>Loading this Helper</h2>
70
71<p>This helper is loaded using the following code:</p>
72<code>$this->load->helper('date');</code>
73
74
75<p>The following functions are available:</p>
76
77<h2>now()</h2>
78
79<p>Returns the current time as a Unix timestamp, referenced either to your server's local time or GMT, based on the "time reference"
80setting in your config file. If you do not intend to set your master time reference to GMT (which you'll typically do if you
81run a site that lets each user set their own timezone settings) there is no benefit to using this function over PHP's time() function.
82</p>
83
84
85
86
87<h2>mdate()</h2>
88
89<p>This function is identical to PHPs <a href="http://www.php.net/date">date()</a> function, except that it lets you
90use MySQL style date codes, where each code letter is preceded with a percent sign: %Y %m %d etc.</p>
91
92<p>The benefit of doing dates this way is that you don't have to worry about escaping any characters that
93are not date codes, as you would normally have to do with the date() function. Example:</p>
94
95<code>$datestring = "Year: %Y Month: %m Day: %d - %h:%i %a";<br />
96$time = time();<br />
97<br />
98echo mdate($datestring, $time);</code>
99
100<p>If a timestamp is not included in the second parameter the current time will be used.</p>
101
102
103<h2>local_to_gmt()</h2>
104
105<p>Takes a Unix timestamp as input and returns it as GMT. Example:</p>
106
107<code>$now = time();<br />
108<br />
109$gmt = local_to_gmt($now);</code>
110
111
112<h2>gmt_to_local()</h2>
113
114<p>Takes a Unix timestamp (referenced to GMT) as input, and converts it to a localized timestamp based on the
115timezone and Daylight Saving time submitted. Example:</p>
116
117<code>
118$timestamp = '1140153693';<br />
119$timezone = 'UM8';<br />
120$daylight_saving = TRUE;<br />
121<br />
122echo gmt_to_local($timestamp, $timezone, daylight_saving);</code>
123
124<p><strong>Note:</strong> For a list of timezones see the reference at the bottom of this page.</p>
125
126<h2>mysql_to_unix()</h2>
127
128<p>Takes a MySQL Timestamp as input and returns it as Unix. Example:</p>
129
130<code>$mysql = '20061124092345';<br />
131<br />
132$unix = mysql_to_unix($mysql);</code>
133
134
135<h2>unix_to_human()</h2>
136
137<p>Takes a Unix timestamp as input and returns it in a human readable format with this prototype:</p>
138
139<code>YYYY-MM-DD HH:MM:SS AM/PM</code>
140
141<p>This can be useful if you need to display a date in a form field for submission.</p>
142
143<p>The time can be formatted with or without seconds, and it can be set to European or US format. If only
144the timestamp is submitted it will return the time without seconds formatted for the U.S. Examples:
145
146<code>$now = time();<br />
147<br />
148echo unix_to_human($now); // U.S. time, no seconds<br />
149<br />
150echo unix_to_human($now, TRUE, 'us'); // U.S. time with seconds<br />
151<br />
152echo unix_to_human($now, TRUE, 'eu'); // Euro time with seconds</code>
153
154
155<h2>human_to_unix()</h2>
156
157<p>The opposite of the above function. Takes a "human" time as input and returns it as Unix. This function is
158useful if you accept "human" formatted dates submitted via a form. Returns FALSE (boolean) if
159the date string passed to it is not formatted as indicated above. Example:</p>
160
161<code>$now = time();<br />
162<br />
163$human = unix_to_human($now);<br />
164<br />
165$unix = human_to_unix($human);</code>
166
167
168
169
170
171<h2>timespan()</h2>
172
173<p>Formats a unix timestamp so that is appears similar to this:</p>
174
175<code>1 Year, 10 Months, 2 Weeks, 5 Days, 10 Hours, 16 Minutes</code>
176
177<p>The first parameter must contain a Unix timestamp. The second parameter must contain a
178timestamp that is greater that the first timesamp. If the second parameter empty, the current time will be used. The most common purpose
179for this function is to show how much time has elapsed from some point in time in the past to now. Example:</p>
180
181<code>$post_date = '1079621429';<br />
182$now = time();<br />
183<br />
184echo timespan($post_date, $now);</code>
185
186<p class="important"><strong>Note:</strong> The text generated by this function is found in the following language file: language/&lt;your_lang&gt;/date_lang.php</p>
187
188
189<h2>days_in_month()</h2>
190
191<p>Returns the number of days in a given month/year. Takes leap years into account. Example:</p>
192<code>echo days_in_month(06, 2005);</code>
193
194<p>If the second parameter is empty, the current year will be used.</p>
195
196
197
198<h2>timezone_menu()</h2>
199
200<p>Generates a pull-down menu of timezones, like this one:</p>
201
202<form>
203<select name="timezones">
204<option value='UM12'>(UTC - 12:00) Enitwetok, Kwajalien</option>
205<option value='UM11'>(UTC - 11:00) Nome, Midway Island, Samoa</option>
206<option value='UM10'>(UTC - 10:00) Hawaii</option>
207<option value='UM9'>(UTC - 9:00) Alaska</option>
208<option value='UM8'>(UTC - 8:00) Pacific Time</option>
209<option value='UM7'>(UTC - 7:00) Mountain Time</option>
210<option value='UM6'>(UTC - 6:00) Central Time, Mexico City</option>
211<option value='UM5'>(UTC - 5:00) Eastern Time, Bogota, Lima, Quito</option>
212<option value='UM4'>(UTC - 4:00) Atlantic Time, Caracas, La Paz</option>
213<option value='UM25'>(UTC - 3:30) Newfoundland</option>
214<option value='UM3'>(UTC - 3:00) Brazil, Buenos Aires, Georgetown, Falkland Is.</option>
215<option value='UM2'>(UTC - 2:00) Mid-Atlantic, Ascention Is., St Helena</option>
216<option value='UM1'>(UTC - 1:00) Azores, Cape Verde Islands</option>
217<option value='UTC' selected='selected'>(UTC) Casablanca, Dublin, Edinburgh, London, Lisbon, Monrovia</option>
218<option value='UP1'>(UTC + 1:00) Berlin, Brussels, Copenhagen, Madrid, Paris, Rome</option>
219<option value='UP2'>(UTC + 2:00) Kaliningrad, South Africa, Warsaw</option>
220<option value='UP3'>(UTC + 3:00) Baghdad, Riyadh, Moscow, Nairobi</option>
221<option value='UP25'>(UTC + 3:30) Tehran</option>
222<option value='UP4'>(UTC + 4:00) Adu Dhabi, Baku, Muscat, Tbilisi</option>
223<option value='UP35'>(UTC + 4:30) Kabul</option>
224<option value='UP5'>(UTC + 5:00) Islamabad, Karachi, Tashkent</option>
225<option value='UP45'>(UTC + 5:30) Bombay, Calcutta, Madras, New Delhi</option>
226<option value='UP6'>(UTC + 6:00) Almaty, Colomba, Dhakra</option>
227<option value='UP7'>(UTC + 7:00) Bangkok, Hanoi, Jakarta</option>
228<option value='UP8'>(UTC + 8:00) Beijing, Hong Kong, Perth, Singapore, Taipei</option>
229<option value='UP9'>(UTC + 9:00) Osaka, Sapporo, Seoul, Tokyo, Yakutsk</option>
230<option value='UP85'>(UTC + 9:30) Adelaide, Darwin</option>
231<option value='UP10'>(UTC + 10:00) Melbourne, Papua New Guinea, Sydney, Vladivostok</option>
232<option value='UP11'>(UTC + 11:00) Magadan, New Caledonia, Solomon Islands</option>
233<option value='UP12'>(UTC + 12:00) Auckland, Wellington, Fiji, Marshall Island</option>
234</select>
235</form>
236
237<p>This menu is useful if you run a membership site in which your users are allowed to set their local timezone value.</p>
238
239<p>The first paramater lets you set the "selected" state of the menu. For example, to set Pacific time as the default you will do this:</p>
240
241<code>echo timezone_menu('UM8');</code>
242
243<p>Please see the timezone reference below to see the values of this menu.</p>
244
245<p>The second parameter lets you set a CSS class name for the menu.</p>
246
247<p class="important"><strong>Note:</strong> The text contained in the menu is found in the following language file: language/&lt;your_lang&gt;/date_lang.php</p>
248
249
250
251<h2>Timezone Reference</h2>
252
253<p>The following table indicates each timezone and its location.</p>
254
255<table cellpadding="0" cellspacing="1" border="0" style="width:100%" class="tableborder">
256<tr>
257<th>Time Zone</th>
258<th>Location</th>
259</tr><tr>
260
261<td class="td">UM12</td><td class="td">(UTC - 12:00) Enitwetok, Kwajalien</td>
262</tr><tr>
263<td class="td">UM11</td><td class="td">(UTC - 11:00) Nome, Midway Island, Samoa</td>
264</tr><tr>
265<td class="td">UM10</td><td class="td">(UTC - 10:00) Hawaii</td>
266</tr><tr>
267<td class="td">UM9</td><td class="td">(UTC - 9:00) Alaska</td>
268</tr><tr>
269<td class="td">UM8</td><td class="td">(UTC - 8:00) Pacific Time</td>
270</tr><tr>
271<td class="td">UM7</td><td class="td">(UTC - 7:00) Mountain Time</td>
272</tr><tr>
273<td class="td">UM6</td><td class="td">(UTC - 6:00) Central Time, Mexico City</td>
274</tr><tr>
275<td class="td">UM5</td><td class="td">(UTC - 5:00) Eastern Time, Bogota, Lima, Quito</td>
276</tr><tr>
277<td class="td">UM4</td><td class="td">(UTC - 4:00) Atlantic Time, Caracas, La Paz</td>
278</tr><tr>
279<td class="td">UM25</td><td class="td">(UTC - 3:30) Newfoundland</td>
280</tr><tr>
281<td class="td">UM3</td><td class="td">(UTC - 3:00) Brazil, Buenos Aires, Georgetown, Falkland Is.</td>
282</tr><tr>
283<td class="td">UM2</td><td class="td">(UTC - 2:00) Mid-Atlantic, Ascention Is., St Helena</td>
284</tr><tr>
285<td class="td">UM1</td><td class="td">(UTC - 1:00) Azores, Cape Verde Islands</td>
286</tr><tr>
287<td class="td">(UTC</td><td class="td">(UTC) Casablanca, Dublin, Edinburgh, London, Lisbon, Monrovia</td>
288</tr><tr>
289<td class="td">UP1</td><td class="td">(UTC + 1:00) Berlin, Brussels, Copenhagen, Madrid, Paris, Rome</td>
290</tr><tr>
291<td class="td">UP2</td><td class="td">(UTC + 2:00) Kaliningrad, South Africa, Warsaw</td>
292</tr><tr>
293<td class="td">UP3</td><td class="td">(UTC + 3:00) Baghdad, Riyadh, Moscow, Nairobi</td>
294</tr><tr>
295<td class="td">UP25</td><td class="td">(UTC + 3:30) Tehran</td>
296</tr><tr>
297<td class="td">UP4</td><td class="td">(UTC + 4:00) Adu Dhabi, Baku, Muscat, Tbilisi</td>
298</tr><tr>
299<td class="td">UP35</td><td class="td">(UTC + 4:30) Kabul</td>
300</tr><tr>
301<td class="td">UP5</td><td class="td">(UTC + 5:00) Islamabad, Karachi, Tashkent</td>
302</tr><tr>
303<td class="td">UP45</td><td class="td">(UTC + 5:30) Bombay, Calcutta, Madras, New Delhi</td>
304</tr><tr>
305<td class="td">UP6</td><td class="td">(UTC + 6:00) Almaty, Colomba, Dhakra</td>
306</tr><tr>
307<td class="td">UP7</td><td class="td">(UTC + 7:00) Bangkok, Hanoi, Jakarta</td>
308</tr><tr>
309<td class="td">UP8</td><td class="td">(UTC + 8:00) Beijing, Hong Kong, Perth, Singapore, Taipei</td>
310</tr><tr>
311<td class="td">UP9</td><td class="td">(UTC + 9:00) Osaka, Sapporo, Seoul, Tokyo, Yakutsk</td>
312</tr><tr>
313<td class="td">UP85</td><td class="td">(UTC + 9:30) Adelaide, Darwin</td>
314</tr><tr>
315<td class="td">UP10</td><td class="td">(UTC + 10:00) Melbourne, Papua New Guinea, Sydney, Vladivostok</td>
316</tr><tr>
317<td class="td">UP11</td><td class="td">(UTC + 11:00) Magadan, New Caledonia, Solomon Islands</td>
318</tr><tr>
319<td class="td">UP12</td><td class="td">(UTC + 12:00) Auckland, Wellington, Fiji, Marshall Island</td>
320</tr>
321</table>
322
323
324</div>
325<!-- END CONTENT -->
326
327
328<div id="footer">
329<p>
330Previous Topic:&nbsp;&nbsp;<a href="cookie_helper.html">Cookie Helper</a>
331&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
332<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
333<a href="../index.html">User Guide Home</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
334Next Topic:&nbsp;&nbsp;<a href="directory_helper.html">Directory Helper</a>
335<p>
336<p><a href="http://www.codeigniter.com">Code Igniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2006 &nbsp;&middot;&nbsp; <a href="http://www.pmachine.com">pMachine, Inc.</a></p>
337</div>
338
339</body>
340</html>