DateUtils
in package

Table of Contents

calcNights()  : int
calcNightsSinceToday()  : int
cloneModify()  : mixed
convertDateFormat()  : mixed
createCheckInDate()  : DateTime|bool
createCheckOutDate()  : DateTime|bool
createDatePeriod()  : DatePeriod
createDateRangeArray()  : array<string|int, mixed>
createDayPeriod()  : mixed
createMonthPeriod()  : mixed
createQuarterPeriod()  : DatePeriod
createThirtyDaysPeriod()  : mixed
createWeekPeriod()  : mixed
createYearPeriod()  : mixed
currentDateWithTime()  : DateTime
dateFormatToRegex()  : mixed
extractDayMonthYear()  : array<string|int, mixed>
formatDateDB()  : string
formatDateTimeDB()  : mixed
formatDateWPFront()  : string
formatModifiedDate()  : string
formatTimeWPFront()  : string
getDayByKey()  : string
getDaysList()  : array<string|int, mixed>
getPostDateTimeUTC()  : false|DateTime
getSiteTimeZone()  : DateTimeZone
isDate()  : mixed
nextTimestampWithTime()  : int
parseTime()  : array<string|int, mixed>

Methods

calcNights()

public static calcNights(DateTime $checkInDate, DateTime $checkOutDate) : int
Parameters
$checkInDate : DateTime
$checkOutDate : DateTime
Tags
note

requires PHP 5 >= 5.3

Return values
int

calcNightsSinceToday()

public static calcNightsSinceToday(DateTime $eventDate) : int
Parameters
$eventDate : DateTime
Tags
since
3.8.3
since
3.9.9

Fix the 'today' date by applying the wordpress site's timezone settings.

Return values
int

cloneModify()

public static cloneModify(DateTime $dateObj, string $modify) : mixed
Parameters
$dateObj : DateTime
$modify : string
Return values
mixed

convertDateFormat()

public static convertDateFormat(string $date[, mixed $inFormat = 'Y-m-d' ][, mixed $outFormat = null ]) : mixed
Parameters
$date : string
$inFormat : mixed = 'Y-m-d'
$outFormat : mixed = null
Return values
mixed

createCheckInDate()

public static createCheckInDate(string $format, string $date[, bool $needSetTime = true ]) : DateTime|bool
Parameters
$format : string

See http://php.net/manual/ru/datetime.formats.php

$date : string
$needSetTime : bool = true
Return values
DateTime|bool

createCheckOutDate()

public static createCheckOutDate(string $format, string $date[, bool $needSetTime = true ]) : DateTime|bool
Parameters
$format : string

See http://php.net/manual/ru/datetime.formats.php

$date : string
$needSetTime : bool = true
Return values
DateTime|bool

createDatePeriod()

public static createDatePeriod(DateTime|string $dateFrom, DateTime|string $dateTo[, bool $includeEndDate = false ]) : DatePeriod
Parameters
$dateFrom : DateTime|string

date in format 'Y-m-d' or \DateTime object

$dateTo : DateTime|string

date in format 'Y-m-d' or \DateTime object

$includeEndDate : bool = false

Optional. Default false.

Tags
warning

PHP <5.3.3 has bug with iterating over DatePeriod twice https://bugs.php.net/bug.php?id=52668

Return values
DatePeriod

createDateRangeArray()

public static createDateRangeArray(DateTime|string $dateFrom, DateTime|string $dateTo[, mixed $includeEndDate = false ]) : array<string|int, mixed>
Parameters
$dateFrom : DateTime|string

date in format 'Y-m-d' or \DateTime object

$dateTo : DateTime|string

date in format 'Y-m-d' or \DateTime object

$includeEndDate : mixed = false
Return values
array<string|int, mixed>

Array of dates representing in front end date format

createDayPeriod()

public static createDayPeriod(DateTime $date) : mixed
Parameters
$date : DateTime

Optional.

Tags
since
3.9.7
Return values
mixed

createMonthPeriod()

public static createMonthPeriod(DateTime $date) : mixed
Parameters
$date : DateTime

Optional.

Tags
since
3.9.7
Return values
mixed

createQuarterPeriod()

public static createQuarterPeriod(int|string $relation[, DateTime|false $baseDate = false ]) : DatePeriod
Parameters
$relation : int|string

Optional.

$baseDate : DateTime|false = false

Optional.

Return values
DatePeriod

createThirtyDaysPeriod()

public static createThirtyDaysPeriod(DateTime $date[, bool $after = false ]) : mixed
Parameters
$date : DateTime

Optional.

$after : bool = false

Optional.

Tags
since
3.9.7
Return values
mixed

createWeekPeriod()

public static createWeekPeriod(DateTime $date[, bool $monday = true ]) : mixed
Parameters
$date : DateTime

Optional.

$monday : bool = true

Optional. Start a week from Monday.

Tags
since
3.9.7
Return values
mixed

createYearPeriod()

public static createYearPeriod(DateTime $date) : mixed
Parameters
$date : DateTime
Return values
mixed

currentDateWithTime()

public static currentDateWithTime(string $time) : DateTime
Parameters
$time : string

Time in 24-hour format.

Return values
DateTime

dateFormatToRegex()

public static dateFormatToRegex(mixed $format) : mixed
Parameters
$format : mixed
Return values
mixed

extractDayMonthYear()

public static extractDayMonthYear(DateTime $date) : array<string|int, mixed>
Parameters
$date : DateTime
Tags
since
3.9.7
Return values
array<string|int, mixed>

[j, n, Y] - date day, month, year

formatDateDB()

public static formatDateDB(DateTime $date) : string
Parameters
$date : DateTime
Return values
string

Date in DB format.

formatDateTimeDB()

public static formatDateTimeDB(DateTime $date) : mixed
Parameters
$date : DateTime
Tags
since
3.9.7
Return values
mixed

formatDateWPFront()

public static formatDateWPFront(DateTime $date) : string
Parameters
$date : DateTime
Return values
string

Localized date in WP format.

formatModifiedDate()

public static formatModifiedDate(DateTime $dateObj, string $format, string $modify) : string
Parameters
$dateObj : DateTime
$format : string
$modify : string
Return values
string

formatTimeWPFront()

public static formatTimeWPFront(DateTime $date) : string
Parameters
$date : DateTime
Return values
string

Localized time in WP format.

getDayByKey()

public static getDayByKey(string $key) : string
Parameters
$key : string
Return values
string

getDaysList()

public static getDaysList() : array<string|int, mixed>
Return values
array<string|int, mixed>

getPostDateTimeUTC()

public static getPostDateTimeUTC(mixed $post) : false|DateTime
Parameters
$post : mixed
Tags
since
3.9.9
Return values
false|DateTime

getSiteTimeZone()

public static getSiteTimeZone() : DateTimeZone
Tags
since
3.9.9
Return values
DateTimeZone

isDate()

public static isDate(mixed $dateString) : mixed
Parameters
$dateString : mixed
Return values
mixed

nextTimestampWithTime()

public static nextTimestampWithTime(string $time) : int
Parameters
$time : string

Time in 24-hour format.

Return values
int

parseTime()

public static parseTime(string $time) : array<string|int, mixed>
Parameters
$time : string

Time in 24-hour format.

Return values
array<string|int, mixed>

["hours" => ..., "minutes" => ...].

Search results