-
Notifications
You must be signed in to change notification settings - Fork 34
classes_base_datetimeex.class
Extends DateTime with sime useful methods.
Extends: DateTime
Calculates the age in x Depending on $unit returns the age of the object in years, months, days, hours, minutes or secods.
Definition: public function Age($unit, $zero_point=false)
Returns: float
The calculated age
Parameters:
-
string $unit
Values: sec, min, hour, day, weeks, month, year -
DateTimeEx $zero_point
The point in time this DateTimeEx object shall be compared to. Defaults to DateTimeEx::Now()
SHORTCUT DateTimeEx::Age(DateTimeEx::SECONDS)
Returns a new DateTimeEx object representing the first day of the month.
If $date
is given that date's first day of month will be returned.
Definition: public static function FirstDayOfMonth($date=false)
Returns: DateTimeEx The created instance
Parameters:
-
mixed $date
Starting point for the calculation
Returns a new DateTimeEx object representing the first day of the week.
If $date
is given that date's first day of week will be returned.
Definition: public static function FirstDayOfWeek($date=false)
Returns: DateTimeEx The created instance
Parameters:
-
mixed $date
Starting point for the calculation
Returns a new DateTimeEx object representing the first day of the year.
If $date
is given that date's first day of year will be returned.
Definition: public static function FirstDayOfYear($date=false)
Returns: DateTimeEx The created instance
Parameters:
-
mixed $date
Starting point for the calculation
SHORTCUT DateTimeEx('Y-m-d\TH:i:s.v').'Z'
Returns a new DateTimeEx from datamatching another Timzone.
Definition: public static function FromOtherTZ($source, $other_timezone, $format=false)
Returns: DateTimeEx
Parameters:
-
mixed $source
DateTimeEx::Make compatible creation data -
string $other_timezone
The timezone $source is from -
string $format
Optional Format, see DateTimeEx::Make
Returns the milliseconds since 1970-01-01 00:00:00.
Definition: public function getTimestampMs()
Returns: int
Checks if this represents a date/time in the future.
That sounds mystic, in fact just return $this > self::Now();
Definition: public function is_future_date(bool $date_only=false)
Returns: bool
true or false
Parameters:
-
bool $date_only
If true compared only the date part (default: false)
Checks if this represents a date/time in the past.
In fact just return $this < self::Now();
Definition: public function is_past_date(bool $date_only=false)
Returns: bool
true or false
Parameters:
-
bool $date_only
If true compared only the date part (default: false)
Checks if this DateTimeEx is today.
Definition: public function is_today()
Returns: bool
True if today, else false
Creates a new DateTimeEx object ready for method chaining.
Definition: public static function Make($source=false, $format=false)
Returns: DateTimeEx The created instance
Parameters:
-
mixed $source
DateTimeEx, DateTime or anything DateTime accepts in it's constructor -
string $format
Optional format to use when parsing $source
Returns the midnight value.
Definition: public function midnight()
Returns: DateTimeEx $this
Returns a new DateTimeEx object representing 'now'.
Definition: public static function Now()
Returns: DateTimeEx The created instance
Adds an offset. Will not modify this object but return a clone. $value and $interval are in fact only separated for good readability:
$dte->Offset(1,'day')->Offset('1 day',''); // all the same
$dte->Offset('1 day ','+ 1 year')->Offset(1,'day + 1 year'); // all the same
Definition: public function Offset($value, $interval)
Returns: DateTimeEx A new instance
Parameters:
-
string $value
See DateInterval::createFromDateString -
string $interval
See DateInterval::createFromDateString
Checks if this object is older than x Best to understand with some samples:
$dte->olderThan(1,'day');
$dte->olderThan(30,'seconds');
$dte->olderThan(15,'months');
Definition: public function olderThan($value, $interval)
Returns: bool
true or false
Parameters:
-
int $value
Offset value -
string $interval
Unit
SHORTCUT DateTimeEx::olderThan($days,DateTimeEx::DAYS)
SHORTCUT DateTimeEx::olderThan($days,DateTimeEx::HOURS)
SHORTCUT DateTimeEx::olderThan($days,DateTimeEx::MINUTES)
Returns a new DateTimeEx object representing the current day at midnight.
Definition: public static function Today()
Returns: DateTimeEx The created instance
Returns this as seem in another timezone.
Definition: public function ToOtherTZ($other_timezone)
Returns: DateTimeEx
Parameters:
-
string $other_timezone
Target timzone
Checks if this object is younger than x Best to understand with some samples:
$dte->youngerThan(1,'day');
$dte->youngerThan(30,'seconds');
$dte->youngerThan(15,'months');
Definition: public function youngerThan($value, $interval)
Returns: bool
true or false
Parameters:
-
int $value
Offset value -
string $interval
Unit
SHORTCUT DateTimeEx::youngerThan($days,DateTimeEx::DAYS)
SHORTCUT DateTimeEx::youngerThan($days,DateTimeEx::HOURS)
SHORTCUT DateTimeEx::youngerThan($days,DateTimeEx::MINUTES)