system/helpersdate_helper.php

CodeIgniter

An open source application development framework for PHP

This content is released under the MIT License (MIT)

Copyright (c) 2014 - 2016, British Columbia Institute of Technology

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Functions

now()

now(  $timezone = NULL) : integer

Get "now" time

Returns time() based on the timezone parameter or on the "time_reference" setting

Parameters

$timezone

Returns

integer

mdate()

mdate(  $datestr = '',   $time = '') : integer

Convert MySQL Style Datecodes

This function is identical to PHPs date() function, except that it allows date codes to be formatted using the MySQL style, where each code letter is preceded with a percent sign: %Y %m %d etc...

The benefit of doing dates this way is that you don't have to worry about escaping your text letters that match the date codes.

Parameters

$datestr
$time

Returns

integer

standard_date()

standard_date(string  $fmt = 'DATE_RFC822', integer  $time = NULL) : string

Standard Date

Returns a date formatted according to the submitted standard.

As of PHP 5.2, the DateTime extension provides constants that serve for the exact same purpose and are used with date().

Parameters

string $fmt

= 'DATE_RFC822' the chosen format

integer $time

= NULL Unix timestamp

Returns

string

Examples

now()); // default
** File not found : date(DATE_RFC822, **
$time); // a different format and time
** File not found : date(DATE_W3C, **

timespan()

timespan(  $seconds = 1,   $time = '',   $units = 7) : string

Timespan

Returns a span of seconds in this format: 10 days 14 hours 36 minutes 47 seconds

Parameters

$seconds
$time
$units

Returns

string

days_in_month()

days_in_month(  $month,   $year = '') : integer

Number of days in a month

Takes a month/year as input and returns the number of days for the given month/year. Takes leap years into consideration.

Parameters

$month
$year

Returns

integer

local_to_gmt()

local_to_gmt(  $time = '') : integer

Converts a local Unix timestamp to GMT

Parameters

$time

Returns

integer

gmt_to_local()

gmt_to_local(  $time = '',   $timezone = 'UTC',   $dst = FALSE) : integer

Converts GMT time to a localized value

Takes a Unix timestamp (in GMT) as input, and returns at the local value based on the timezone and DST setting submitted

Parameters

$time
$timezone
$dst

Returns

integer

mysql_to_unix()

mysql_to_unix(  $time = '') : integer

Converts a MySQL Timestamp to Unix

Parameters

$time

Returns

integer —

Unix timstamp

unix_to_human()

unix_to_human(  $time = '',   $seconds = FALSE,   $fmt = 'us') : string

Unix to "Human"

Formats Unix timestamp to the following prototype: 2006-08-21 11:35 PM

Parameters

$time
$seconds
$fmt

Returns

string

human_to_unix()

human_to_unix(  $datestr = '') : integer

Convert "human" date to GMT

Reverses the above process

Parameters

$datestr

Returns

integer

nice_date()

nice_date(  $bad_date = '',   $format = FALSE) : string

Turns many "reasonably-date-like" strings into something that is actually useful. This only works for dates after unix epoch.

Parameters

$bad_date
$format

Returns

string

timezone_menu()

timezone_menu(  $default = 'UTC',   $class = '',   $name = 'timezones',   $attributes = '') : string

Timezone Menu

Generates a drop-down menu of timezones.

Parameters

$default
$class
$name
$attributes

Returns

string

timezones()

timezones(  $tz = '') : string

Timezones

Returns an array of timezones. This is a helper function for various other ones in this library

Parameters

$tz

Returns

string

date_range()

date_range(  $unix_start = '',   $mixed = '',   $is_unix = TRUE,   $format = 'Y-m-d') : array

Date range

Returns a list of dates within a specified period.

Parameters

$unix_start
$mixed
$is_unix
$format

Returns

array