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