class Date (View source)

Constants

CALENDAR_WINDOWS_1900

constants

CALENDAR_MAC_1904

Properties

static string[] $monthNames Names of the months of the year, indexed by shortname Planned usage for locale settings.
static string[] $numberSuffixes
static protected int $excelCalendar Base calendar year to use for calculations Value is either CALENDAR_WINDOWS_1900 (1900) or CALENDAR_MAC_1904 (1904).
static protected null|DateTimeZone $defaultTimeZone Default timezone to use for DateTime objects.

Methods

static bool
setExcelCalendar(int $baseDate)

Set the Excel calendar (Windows 1900 or Mac 1904).

static int
getExcelCalendar()

Return the Excel calendar (Windows 1900 or Mac 1904).

static bool
setDefaultTimezone(DateTimeZone|string $timeZone)

Set the Default timezone to use for dates.

static DateTimeZone
getDefaultTimezone()

Return the Default timezone being used for dates.

static DateTimeZone
validateTimeZone(DateTimeZone|string $timeZone)

Validate a timezone.

static DateTime
excelToDateTimeObject(float|int $excelTimestamp, null|DateTimeZone|string $timeZone = null)

Convert a MS serialized datetime value from Excel to a PHP Date/Time object.

static int
excelToTimestamp(float|int $excelTimestamp, null|DateTimeZone|string $timeZone = null)

Convert a MS serialized datetime value from Excel to a unix timestamp.

static bool|float
PHPToExcel(mixed $dateValue)

Convert a date from PHP to an MS Excel serialized date/time value.

static float
dateTimeToExcel(DateTimeInterface $dateValue)

Convert a PHP DateTime object to an MS Excel serialized date/time value.

static float
timestampToExcel(int $dateValue)

Convert a Unix timestamp to an MS Excel serialized date/time value.

static float
formattedPHPToExcel(int $year, int $month, int $day, int $hours = 0, int $minutes = 0, int $seconds = 0)

formattedPHPToExcel.

static bool
isDateTime(Cell $pCell)

Is a given cell a date/time?

static bool
isDateTimeFormat(NumberFormat $pFormat)

Is a given number format a date/time?

static bool
isDateTimeFormatCode(string $pFormatCode)

Is a given number format code a date/time?

static false|float
stringToExcel(string $dateValue)

Convert a date/time string to Excel time.

static int|string
monthStringToNumber(string $month)

Converts a month name (either a long or a short name) to a month number.

static int|string
dayStringToNumber(string $day)

Strips an ordinal from a numeric value.

Details

static bool setExcelCalendar(int $baseDate)

Set the Excel calendar (Windows 1900 or Mac 1904).

Parameters

int $baseDate Excel base date (1900 or 1904)

Return Value

bool Success or failure

static int getExcelCalendar()

Return the Excel calendar (Windows 1900 or Mac 1904).

Return Value

int Excel base date (1900 or 1904)

static bool setDefaultTimezone(DateTimeZone|string $timeZone)

Set the Default timezone to use for dates.

Parameters

DateTimeZone|string $timeZone The timezone to set for all Excel datetimestamp to PHP DateTime Object conversions

Return Value

bool Success or failure

Exceptions

Exception

static DateTimeZone getDefaultTimezone()

Return the Default timezone being used for dates.

Return Value

DateTimeZone The timezone being used as default for Excel timestamp to PHP DateTime object

static protected DateTimeZone validateTimeZone(DateTimeZone|string $timeZone)

Validate a timezone.

Parameters

DateTimeZone|string $timeZone The timezone to validate, either as a timezone string or object

Return Value

DateTimeZone The timezone as a timezone object

Exceptions

Exception

static DateTime excelToDateTimeObject(float|int $excelTimestamp, null|DateTimeZone|string $timeZone = null)

Convert a MS serialized datetime value from Excel to a PHP Date/Time object.

Parameters

float|int $excelTimestamp MS Excel serialized date/time value
null|DateTimeZone|string $timeZone The timezone to assume for the Excel timestamp, if you don't want to treat it as a UTC value Use the default (UST) unless you absolutely need a conversion

Return Value

DateTime PHP date/time object

Exceptions

Exception

static int excelToTimestamp(float|int $excelTimestamp, null|DateTimeZone|string $timeZone = null)

Convert a MS serialized datetime value from Excel to a unix timestamp.

Parameters

float|int $excelTimestamp MS Excel serialized date/time value
null|DateTimeZone|string $timeZone The timezone to assume for the Excel timestamp, if you don't want to treat it as a UTC value Use the default (UST) unless you absolutely need a conversion

Return Value

int Unix timetamp for this date/time

Exceptions

Exception

static bool|float PHPToExcel(mixed $dateValue)

Convert a date from PHP to an MS Excel serialized date/time value.

Parameters

mixed $dateValue Unix Timestamp or PHP DateTime object or a string

Return Value

bool|float Excel date/time value or boolean FALSE on failure

static float dateTimeToExcel(DateTimeInterface $dateValue)

Convert a PHP DateTime object to an MS Excel serialized date/time value.

Parameters

DateTimeInterface $dateValue PHP DateTime object

Return Value

float MS Excel serialized date/time value

static float timestampToExcel(int $dateValue)

Convert a Unix timestamp to an MS Excel serialized date/time value.

Parameters

int $dateValue Unix Timestamp

Return Value

float MS Excel serialized date/time value

static float formattedPHPToExcel(int $year, int $month, int $day, int $hours = 0, int $minutes = 0, int $seconds = 0)

formattedPHPToExcel.

Parameters

int $year
int $month
int $day
int $hours
int $minutes
int $seconds

Return Value

float Excel date/time value

static bool isDateTime(Cell $pCell)

Is a given cell a date/time?

Parameters

Cell $pCell

Return Value

bool

static bool isDateTimeFormat(NumberFormat $pFormat)

Is a given number format a date/time?

Parameters

NumberFormat $pFormat

Return Value

bool

static bool isDateTimeFormatCode(string $pFormatCode)

Is a given number format code a date/time?

Parameters

string $pFormatCode

Return Value

bool

static false|float stringToExcel(string $dateValue)

Convert a date/time string to Excel time.

Parameters

string $dateValue Examples: '2009-12-31', '2009-12-31 15:59', '2009-12-31 15:59:10'

Return Value

false|float Excel date/time serial value

static int|string monthStringToNumber(string $month)

Converts a month name (either a long or a short name) to a month number.

Parameters

string $month Month name or abbreviation

Return Value

int|string Month number (1 - 12), or the original string argument if it isn't a valid month name

static int|string dayStringToNumber(string $day)

Strips an ordinal from a numeric value.

Parameters

string $day Day number with an ordinal

Return Value

int|string The integer value with any ordinal stripped, or the original string argument if it isn't a valid numeric