Date_Time_Converter
in package
Date and Time Converter by Elac v0.9.3 elacdude@gmail.com www.elacdude.com
You are free to use this code free of charge, modify it, and distrubute it, just leave this comment block at the top of this file.
Changes/Modifications 6/24/08 - Version 0.9.2 released. Minor additions - Added "S" support. (th, rd, st, nd. example: 5th) - Added a few more abbreviations for units of time in calculate() (s. sec. secs. min. mins. m. and more) - Added example.php (php examples and usage) and date_time_formats.html (list of supported date/time formats) to the package. 6/25/08 - Version 0.9.3 released. Bug fixes - Fixed month subtraction (wrap to previous year) bug - Fixed month and year "$only_return_the_value=true" bug. If you calculated by months or years, and set $only_return_the_value=true, it would overwrite the values instead of just returning them. - Fixed the "D" (Sun, Mon, Tue) bug. If you supplied "D" and "d" in the same mask, it would not return the correct output. - Changed the names of public variables "day", "month", and "year" added "s" at the end for consistency purposes 11/14/08 - Version 0.9.4 released. Bug fix - Got rid of the _one_dig_num function and used ltrim($num "0") instead
Table of Contents
Properties
- $ampm : mixed
- $date_time : string
- The date to be calculated. ex: 12/30/2008 17:40:00
- $date_time_mask : string
- The php date() style format that $date_time is in. ex: m/d/Y H:i:s
- $date_time_stamp : mixed
- The date to be calculated in timestamp format
- $days : mixed
- $hours : mixed
- $minutes : mixed
- $months : mixed
- $seconds : mixed
- $years : mixed
Methods
- __construct() : mixed
- Constructor. This is where you supply the date. Accepts almost any format of date as long as you supply the correct mask. DOES accept dates without leading zeros (n,j,g,G) as long as they aren't bunched together.
- __destruct() : mixed
- convert() : mixed
- Sets a new format/mask for the date using the php date() style formatting Example: $obj->convert("M j Y H:i:s A");
- set_date_time() : mixed
- Changes the date to a new one.
- _date_to_timestamp() : mixed
- Private Function. Converts a date into a timestamp. Accepts almost any format of date as long as you supply the correct mask. DOES accept dates without leading zeros (n,j,g,G) as long as they aren't bunched together.
- _default_date_time_units() : mixed
- Private function. Resets date and time unit variables to default
- _month_num() : mixed
- Private Function. Converts a textual month into a digit. Accepts almost any textual format of a month including abbreviations.
Properties
$ampm
public
mixed
$ampm
$date_time
The date to be calculated. ex: 12/30/2008 17:40:00
public
string
$date_time
$date_time_mask
The php date() style format that $date_time is in. ex: m/d/Y H:i:s
public
string
$date_time_mask
$date_time_stamp
The date to be calculated in timestamp format
public
mixed
$date_time_stamp
$days
public
mixed
$days
$hours
public
mixed
$hours
$minutes
public
mixed
$minutes
$months
public
mixed
$months
$seconds
public
mixed
$seconds
$years
public
mixed
$years
Methods
__construct()
Constructor. This is where you supply the date. Accepts almost any format of date as long as you supply the correct mask. DOES accept dates without leading zeros (n,j,g,G) as long as they aren't bunched together.
public
__construct(mixed $sDate, mixed $sFormat) : mixed
ie: ("1152008", "njY") wont work; ("1/15/2008", "n/j/2008") will work. Example: $obj = new Date_Time_Calc('12/30/2008 17:40:00', 'm/d/Y H:i:s');
Parameters
- $sDate : mixed
- $sFormat : mixed
__destruct()
public
__destruct() : mixed
convert()
Sets a new format/mask for the date using the php date() style formatting Example: $obj->convert("M j Y H:i:s A");
public
convert(mixed $new_mask[, mixed $save = true ]) : mixed
Parameters
- $new_mask : mixed
- $save : mixed = true
set_date_time()
Changes the date to a new one.
public
set_date_time(mixed $start_date_time, mixed $mask) : mixed
Example: $obj->set_date_time('11/20/2005 07:40:00 AM', 'm/d/Y H:i:s A');
Parameters
- $start_date_time : mixed
- $mask : mixed
_date_to_timestamp()
Private Function. Converts a date into a timestamp. Accepts almost any format of date as long as you supply the correct mask. DOES accept dates without leading zeros (n,j,g,G) as long as they aren't bunched together.
private
_date_to_timestamp(mixed $thedate, mixed $mask) : mixed
ie: ("1152008", "njY") wont work; ("1/15/2008", "n/j/2008") will work
Parameters
- $thedate : mixed
- $mask : mixed
_default_date_time_units()
Private function. Resets date and time unit variables to default
private
_default_date_time_units() : mixed
_month_num()
Private Function. Converts a textual month into a digit. Accepts almost any textual format of a month including abbreviations.
private
_month_num(mixed $themonth[, mixed $return_two_digit = false ]) : mixed
Example: _month_num("jan"); //returns '1' Example2: _month_num("january", true); //returns '01'
Parameters
- $themonth : mixed
- $return_two_digit : mixed = false