Date helper

Date::offset

Returns the offset (in seconds) between two time zones. Use this to display dates to users in different time zones.

Parameters

  • $remote (string): Timezone that to find the offset of (See Timezones)
  • $local (string): Timezone used as the baseline (See Timezones)
  • $now (mixed): Unix timestamp or date string

Returns

  • integer

Example

$seconds = Date::offset('America/Chicago', 'GMT');

Date::seconds

Number of seconds in a minute, incrementing by a step. Typically used as a shortcut for generating a list that can used in a form.

Params

  • $step (integer): Amount to increment each step by, 1 to 30 (Default 1)
  • $start (integer): Start value
  • $end (integer): End value

Returns

  • array: A mirrored (foo => foo) array from 1-60

Example

    $seconds = Date::seconds();  // 01, 02, 03, ..., 58, 59, 60

Date::minutes

Number of minutes in an hour, incrementing by a step. Typically used as a shortcut for generating a list that can be used in a form.

Parameters

  • $step (integer): Amount to increment each step by, 1 to 30 (Default value 5)

Returns

  • array: A mirrored (foo => foo) array from 1-60

Example

    $minutes = Date::minutes(); // 05, 10, 15, ..., 50, 55, 60

Date::hours

Number of hours in a day. Typically used as a shortcut for generating a list.

Parameters

  • $step (integer): Amount to increment each step by (Default 1)
  • $long (bool): Use 24-hour time (Default false)
  • $start (integer): The hour to start at (Default null)

Returns

  • array: A mirrored (foo => foo) array from 1-60

Example

    $hours = Date::hours(); // 01, 02, 03, ..., 10, 11, 12

Date::ampm

Returns AM or PM, based on a given hour (in 24 hour format).

Parameters

  • $hour (integer): Number of the hour

Returns

  • string

Example

    $type = Date::ampm(12); // PM $type = Date::ampm(1); // AM

Date::adjust

Adjusts a non-24-hour number into a 24-hour number.

Parameters

  • $hour (integer): Hour to adjust
  • $ampm (string): AM or PM

Returns

  • string

Example

    $hour = Date::adjust(3, 'pm'); // 15

Date::days

Number of days in a given month and year. Typically used as a shortcut for generating a list that can be used in a form.

Parameters

  • $month (integer): Number of month
  • $year (integer): Number of the year to check month (Default current year)

Returns

  • array: A mirrored (foo => foo) array of the days

Example

    Date::days(4, 2017); // 1, 2, 3, ..., 28

Date::months

Number of months in a year. Typically used as a shortcut for generating a list.

Parameters

  • $format (string): The format to use for months

Returns

  • array: An array of the months based on the specified format

Example

    // By default a mirrored array of $month_number => $month_number is returned
    Date::months(); // [1 => 1, 2 => 2, 3 => 3, ..., 12 => 12]

    // But you can customize this by passing in either Date:;MONTHS_LONG
    Date::months(Date::MONTHS_LONG); // [1 => 'January', 2 => 'February'...]

    // or Date::MONTHS_SHORT
    Date::months(Date::MONTHS_SHORT); // [1 => 'Jan', 2 => 'Feb'...]

Date::years

Returns an array of years between a starting and ending year. By default, the the current year - 5 and current year + 5 will be used. Typically used as a shortcut for generating a list.

Parameters

  • $start (integer): Starting year (Default is current year - 5)
  • $end (integer): Ending year (Default is current year + 5);

Returns

  • array

Example

    $years = Date::years(2000, 2010); // 2000, 2001, ..., 2009, 2010

Date::span

Returns time difference between two timestamps, in human readable format. If the second timestamp is not given, the current time will be used. Also consider using [Date::fuzzy_span] when displaying a span.

Parameters

  • $remote (integer): Timestamp to find the span of
  • $local (integer): Timestamp to use as the baseline (Default null = current timestamp)
  • $output (string): Formatting

Returns

  • string: When only a single output is requested
  • array: Associative list of all outputs requested

Example

    $span = Date::span(60, 182, 'minutes,seconds'); // array('minutes' => 2, 'seconds' => 2) 
    $span = Date::span(60, 182, 'minutes'); // 2

Date::fuzzy_span

Returns the difference between a time and now in a "fuzzy" way. Displaying a fuzzy time instead of a date is usually faster to read and understand.

Parameters

  • $timestamp (integer): Remote timestamp
  • $local_timestamp (integer): Local timestamp (Default current timestamp)

Returns

  • string

Example

    $span = Date::fuzzy_span(time() - 10); // "moments ago" 
    $span = Date::fuzzy_span(time() + 20); // "in moments"

Date::formatted_time

Returns a date/time string with the specified timestamp format.

Parameters

  • $datetime_str (string): Datetime string (Default 'now');
  • $timestamp_format (string): Timestamp format (See Datetime)
  • $timezone (string): Timezone identifier (Default current timezone, see Timezones)

Returns

  • string

Example

    $time = Date::formatted_time('5 minutes ago');