Date
in package
Table of Contents
Constants
- CALENDAR_MAC_1904 = 1904
- CALENDAR_WINDOWS_1900 = 1900
- constants
- POSSIBLE_DATETIME_FORMAT_CHARACTERS = 'eymdHs'
- POSSIBLE_TIME_FORMAT_CHARACTERS = 'Hs'
Properties
- $monthNames : array<string|int, string>
- Names of the months of the year, indexed by shortname Planned usage for locale settings.
- $numberSuffixes : array<string|int, string>
- $defaultTimeZone : DateTimeZone|null
- Default timezone to use for DateTime objects.
- $excelCalendar : int
- Base calendar year to use for calculations Value is either CALENDAR_WINDOWS_1900 (1900) or CALENDAR_MAC_1904 (1904).
Methods
- convertIsoDate() : float|int
- dateTimeFromTimestamp() : DateTime
- dateTimeToExcel() : float
- Convert a PHP DateTime object to an MS Excel serialized date/time value.
- dayStringToNumber() : int|string
- Strips an ordinal from a numeric value.
- excelToDateTimeObject() : DateTime
- Convert a MS serialized datetime value from Excel to a PHP Date/Time object.
- excelToTimestamp() : int
- Convert a MS serialized datetime value from Excel to a unix timestamp.
- formattedDateTimeFromTimestamp() : string
- formattedPHPToExcel() : float
- formattedPHPToExcel.
- getDefaultOrLocalTimezone() : DateTimeZone
- Return the Default timezone, or local timezone if default is not set.
- getDefaultTimezone() : DateTimeZone
- Return the Default timezone, or UTC if default not set.
- getDefaultTimezoneOrNull() : DateTimeZone|null
- Return the Default timezone even if null.
- getExcelCalendar() : int
- Return the Excel calendar (Windows 1900 or Mac 1904).
- isDateTime() : bool
- Is a given cell a date/time?
- isDateTimeFormat() : bool
- Is a given NumberFormat code a date/time format code?
- isDateTimeFormatCode() : bool
- Is a given number format code a date/time?
- monthStringToNumber() : int|string
- Converts a month name (either a long or a short name) to a month number.
- PHPToExcel() : false|float
- Convert a date from PHP to an MS Excel serialized date/time value.
- roundMicroseconds() : void
- Round the given DateTime object to seconds.
- setDefaultTimezone() : bool
- Set the Default timezone to use for dates.
- setExcelCalendar() : bool
- Set the Excel calendar (Windows 1900 or Mac 1904).
- stringToExcel() : false|float
- Convert a date/time string to Excel time.
- timestampToExcel() : false|float
- Convert a Unix timestamp to an MS Excel serialized date/time value.
- validateTimeZone() : DateTimeZone|null
- Validate a timezone.
Constants
CALENDAR_MAC_1904
public
mixed
CALENDAR_MAC_1904
= 1904
CALENDAR_WINDOWS_1900
constants
public
mixed
CALENDAR_WINDOWS_1900
= 1900
POSSIBLE_DATETIME_FORMAT_CHARACTERS
private
mixed
POSSIBLE_DATETIME_FORMAT_CHARACTERS
= 'eymdHs'
POSSIBLE_TIME_FORMAT_CHARACTERS
private
mixed
POSSIBLE_TIME_FORMAT_CHARACTERS
= 'Hs'
Properties
$monthNames
Names of the months of the year, indexed by shortname Planned usage for locale settings.
public
static array<string|int, string>
$monthNames
= ['Jan' => 'January', 'Feb' => 'February', 'Mar' => 'March', 'Apr' => 'April', 'May' => 'May', 'Jun' => 'June', 'Jul' => 'July', 'Aug' => 'August', 'Sep' => 'September', 'Oct' => 'October', 'Nov' => 'November', 'Dec' => 'December']
$numberSuffixes
public
static array<string|int, string>
$numberSuffixes
= ['st', 'nd', 'rd', 'th']
$defaultTimeZone
Default timezone to use for DateTime objects.
protected
static DateTimeZone|null
$defaultTimeZone
= null
$excelCalendar
Base calendar year to use for calculations Value is either CALENDAR_WINDOWS_1900 (1900) or CALENDAR_MAC_1904 (1904).
protected
static int
$excelCalendar
= self::CALENDAR_WINDOWS_1900
Methods
convertIsoDate()
public
static convertIsoDate(mixed $value) : float|int
Parameters
- $value : mixed
-
Converts a date/time in ISO-8601 standard format date string to an Excel serialized timestamp. See https://en.wikipedia.org/wiki/ISO_8601 for details of the ISO-8601 standard format.
Return values
float|intdateTimeFromTimestamp()
public
static dateTimeFromTimestamp(string $date[, DateTimeZone|null $timeZone = null ]) : DateTime
Parameters
- $date : string
- $timeZone : DateTimeZone|null = null
Return values
DateTimedateTimeToExcel()
Convert a PHP DateTime object to an MS Excel serialized date/time value.
public
static dateTimeToExcel(DateTimeInterface $dateValue) : float
Parameters
- $dateValue : DateTimeInterface
-
PHP DateTime object
Return values
float —MS Excel serialized date/time value
dayStringToNumber()
Strips an ordinal from a numeric value.
public
static dayStringToNumber(string $day) : int|string
Parameters
- $day : string
-
Day number with an ordinal
Return values
int|string —The integer value with any ordinal stripped, or the original string argument if it isn't a valid numeric
excelToDateTimeObject()
Convert a MS serialized datetime value from Excel to a PHP Date/Time object.
public
static excelToDateTimeObject(float|int $excelTimestamp[, null|DateTimeZone|string $timeZone = null ]) : DateTime
Parameters
- $excelTimestamp : float|int
-
MS Excel serialized date/time value
- $timeZone : null|DateTimeZone|string = null
-
The timezone to assume for the Excel timestamp, if you don't want to treat it as a UTC value Use the default (UTC) unless you absolutely need a conversion
Return values
DateTime —PHP date/time object
excelToTimestamp()
Convert a MS serialized datetime value from Excel to a unix timestamp.
public
static excelToTimestamp(float|int $excelTimestamp[, null|DateTimeZone|string $timeZone = null ]) : int
The use of Unix timestamps, and therefore this function, is discouraged. They are not Y2038-safe on a 32-bit system, and have no timezone info.
Parameters
- $excelTimestamp : float|int
-
MS Excel serialized date/time value
- $timeZone : null|DateTimeZone|string = null
-
The timezone to assume for the Excel timestamp, if you don't want to treat it as a UTC value Use the default (UTC) unless you absolutely need a conversion
Return values
int —Unix timetamp for this date/time
formattedDateTimeFromTimestamp()
public
static formattedDateTimeFromTimestamp(string $date, string $format[, DateTimeZone|null $timeZone = null ]) : string
Parameters
- $date : string
- $format : string
- $timeZone : DateTimeZone|null = null
Return values
stringformattedPHPToExcel()
formattedPHPToExcel.
public
static formattedPHPToExcel(int $year, int $month, int $day[, int $hours = 0 ][, int $minutes = 0 ][, float|int $seconds = 0 ]) : float
Parameters
- $year : int
- $month : int
- $day : int
- $hours : int = 0
- $minutes : int = 0
- $seconds : float|int = 0
Return values
float —Excel date/time value
getDefaultOrLocalTimezone()
Return the Default timezone, or local timezone if default is not set.
public
static getDefaultOrLocalTimezone() : DateTimeZone
Return values
DateTimeZonegetDefaultTimezone()
Return the Default timezone, or UTC if default not set.
public
static getDefaultTimezone() : DateTimeZone
Return values
DateTimeZonegetDefaultTimezoneOrNull()
Return the Default timezone even if null.
public
static getDefaultTimezoneOrNull() : DateTimeZone|null
Return values
DateTimeZone|nullgetExcelCalendar()
Return the Excel calendar (Windows 1900 or Mac 1904).
public
static getExcelCalendar() : int
Return values
int —Excel base date (1900 or 1904)
isDateTime()
Is a given cell a date/time?
public
static isDateTime(Cell $cell[, mixed $value = null ][, bool $dateWithoutTimeOkay = true ]) : bool
Parameters
- $cell : Cell
- $value : mixed = null
- $dateWithoutTimeOkay : bool = true
Return values
boolisDateTimeFormat()
Is a given NumberFormat code a date/time format code?
public
static isDateTimeFormat(NumberFormat $excelFormatCode[, bool $dateWithoutTimeOkay = true ]) : bool
Parameters
- $excelFormatCode : NumberFormat
- $dateWithoutTimeOkay : bool = true
Return values
boolisDateTimeFormatCode()
Is a given number format code a date/time?
public
static isDateTimeFormatCode(string $excelFormatCode[, bool $dateWithoutTimeOkay = true ]) : bool
Parameters
- $excelFormatCode : string
- $dateWithoutTimeOkay : bool = true
Return values
boolmonthStringToNumber()
Converts a month name (either a long or a short name) to a month number.
public
static monthStringToNumber(string $monthName) : int|string
Parameters
- $monthName : string
-
Month name or abbreviation
Return values
int|string —Month number (1 - 12), or the original string argument if it isn't a valid month name
PHPToExcel()
Convert a date from PHP to an MS Excel serialized date/time value.
public
static PHPToExcel(mixed $dateValue) : false|float
Parameters
- $dateValue : mixed
-
PHP DateTime object or a string - Unix timestamp is also permitted, but discouraged; not Y2038-safe on a 32-bit system, and no timezone info
Return values
false|float —Excel date/time value or boolean FALSE on failure
roundMicroseconds()
Round the given DateTime object to seconds.
public
static roundMicroseconds(DateTime $dti) : void
Parameters
- $dti : DateTime
setDefaultTimezone()
Set the Default timezone to use for dates.
public
static setDefaultTimezone(null|DateTimeZone|string $timeZone) : bool
Parameters
- $timeZone : null|DateTimeZone|string
-
The timezone to set for all Excel datetimestamp to PHP DateTime Object conversions
Return values
bool —Success or failure
setExcelCalendar()
Set the Excel calendar (Windows 1900 or Mac 1904).
public
static setExcelCalendar(int|null $baseYear) : bool
Parameters
- $baseYear : int|null
-
Excel base date (1900 or 1904)
Return values
bool —Success or failure
stringToExcel()
Convert a date/time string to Excel time.
public
static stringToExcel(string $dateValue) : false|float
Parameters
- $dateValue : string
-
Examples: '2009-12-31', '2009-12-31 15:59', '2009-12-31 15:59:10'
Return values
false|float —Excel date/time serial value
timestampToExcel()
Convert a Unix timestamp to an MS Excel serialized date/time value.
public
static timestampToExcel(float|int|string $unixTimestamp) : false|float
The use of Unix timestamps, and therefore this function, is discouraged. They are not Y2038-safe on a 32-bit system, and have no timezone info.
Parameters
- $unixTimestamp : float|int|string
-
Unix Timestamp
Return values
false|float —MS Excel serialized date/time value
validateTimeZone()
Validate a timezone.
private
static validateTimeZone(null|DateTimeZone|string $timeZone) : DateTimeZone|null
Parameters
- $timeZone : null|DateTimeZone|string
-
The timezone to validate, either as a timezone string or object
Return values
DateTimeZone|null —The timezone as a timezone object