Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]

(no description)

File Size: 915 lines (35 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

DateTime:: (25 methods):
  isLeapYear()
  getDateValue()
  DATETIMENOW()
  DATENOW()
  DATE()
  TIME()
  DATEVALUE()
  TIMEVALUE()
  DATEDIF()
  DAYS()
  DAYS360()
  YEARFRAC()
  NETWORKDAYS()
  WORKDAY()
  DAYOFMONTH()
  WEEKDAY()
  WEEKNUM()
  ISOWEEKNUM()
  MONTHOFYEAR()
  YEAR()
  HOUROFDAY()
  MINUTE()
  SECOND()
  EDATE()
  EOMONTH()


Class: DateTime  - X-Ref


isLeapYear($year)   X-Ref
Identify if a year is a leap year or not.

return: bool TRUE if the year is a leap year, otherwise FALSE
param: int|string $year The year to test

getDateValue($dateValue)   X-Ref
getDateValue.

return: mixed Excel date/time serial value, or string if error
param: mixed $dateValue

DATETIMENOW()   X-Ref
DATETIMENOW.

Returns the current date and time.
The NOW function is useful when you need to display the current date and time on a worksheet or
calculate a value based on the current date and time, and have that value updated each time you
open the worksheet.

NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
and time format of your regional settings. PhpSpreadsheet does not change cell formatting in this way.

Excel Function:
NOW()

return: mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,

DATENOW()   X-Ref
DATENOW.

Returns the current date.
The NOW function is useful when you need to display the current date and time on a worksheet or
calculate a value based on the current date and time, and have that value updated each time you
open the worksheet.

NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
and time format of your regional settings. PhpSpreadsheet does not change cell formatting in this way.

Excel Function:
TODAY()

return: mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,

DATE($year = 0, $month = 1, $day = 1)   X-Ref
DATE.

The DATE function returns a value that represents a particular date.

NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
format of your regional settings. PhpSpreadsheet does not change cell formatting in this way.


Excel Function:
DATE(year,month,day)

return: mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
param: int $year The value of the year argument can include one to four digits.
param: int $month A positive or negative integer representing the month of the year
param: int $day A positive or negative integer representing the day of the month

TIME($hour = 0, $minute = 0, $second = 0)   X-Ref
TIME.

The TIME function returns a value that represents a particular time.

NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the time
format of your regional settings. PhpSpreadsheet does not change cell formatting in this way.

Excel Function:
TIME(hour,minute,second)

return: mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
param: int $hour A number from 0 (zero) to 32767 representing the hour.
param: int $minute A number from 0 to 32767 representing the minute.
param: int $second A number from 0 to 32767 representing the second.

DATEVALUE($dateValue)   X-Ref
DATEVALUE.

Returns a value that represents a particular date.
Use DATEVALUE to convert a date represented by a text string to an Excel or PHP date/time stamp
value.

NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
format of your regional settings. PhpSpreadsheet does not change cell formatting in this way.

Excel Function:
DATEVALUE(dateValue)

return: mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
param: string $dateValue Text that represents a date in a Microsoft Excel date format.

TIMEVALUE($timeValue)   X-Ref
TIMEVALUE.

Returns a value that represents a particular time.
Use TIMEVALUE to convert a time represented by a text string to an Excel or PHP date/time stamp
value.

NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the time
format of your regional settings. PhpSpreadsheet does not change cell formatting in this way.

Excel Function:
TIMEVALUE(timeValue)

return: mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
param: string $timeValue A text string that represents a time in any one of the Microsoft

DATEDIF($startDate = 0, $endDate = 0, $unit = 'D')   X-Ref
DATEDIF.

Excel Function:
DATEDIF(startdate, enddate, unit)

return: int|string Interval between the dates
param: mixed $startDate Excel date serial value, PHP date/time stamp, PHP DateTime object
param: mixed $endDate Excel date serial value, PHP date/time stamp, PHP DateTime object
param: string $unit

DAYS($endDate = 0, $startDate = 0)   X-Ref
DAYS.

Returns the number of days between two dates

Excel Function:
DAYS(endDate, startDate)

return: int|string Number of days between start date and end date or an error
param: DateTimeInterface|float|int|string $endDate Excel date serial value (float),
param: DateTimeInterface|float|int|string $startDate Excel date serial value (float),

DAYS360($startDate = 0, $endDate = 0, $method = false)   X-Ref
DAYS360.

Returns the number of days between two dates based on a 360-day year (twelve 30-day months),
which is used in some accounting calculations. Use this function to help compute payments if
your accounting system is based on twelve 30-day months.

Excel Function:
DAYS360(startDate,endDate[,method])

return: int|string Number of days between start date and end date
param: mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
param: mixed $endDate Excel date serial value (float), PHP date timestamp (integer),
param: bool $method US or European Method

YEARFRAC($startDate = 0, $endDate = 0, $method = 0)   X-Ref
YEARFRAC.

Calculates the fraction of the year represented by the number of whole days between two dates
(the start_date and the end_date).
Use the YEARFRAC worksheet function to identify the proportion of a whole year's benefits or
obligations to assign to a specific term.

Excel Function:
YEARFRAC(startDate,endDate[,method])

return: float|string fraction of the year, or a string containing an error
param: mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
param: mixed $endDate Excel date serial value (float), PHP date timestamp (integer),
param: int $method Method used for the calculation

NETWORKDAYS($startDate, $endDate, ...$dateArgs)   X-Ref
NETWORKDAYS.

Returns the number of whole working days between start_date and end_date. Working days
exclude weekends and any dates identified in holidays.
Use NETWORKDAYS to calculate employee benefits that accrue based on the number of days
worked during a specific term.

Excel Function:
NETWORKDAYS(startDate,endDate[,holidays[,holiday[,...]]])

return: int|string Interval between the dates
param: mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
param: mixed $endDate Excel date serial value (float), PHP date timestamp (integer),
param: mixed $dateArgs

WORKDAY($startDate, $endDays, ...$dateArgs)   X-Ref
WORKDAY.

Returns the date that is the indicated number of working days before or after a date (the
starting date). Working days exclude weekends and any dates identified as holidays.
Use WORKDAY to exclude weekends or holidays when you calculate invoice due dates, expected
delivery times, or the number of days of work performed.

Excel Function:
WORKDAY(startDate,endDays[,holidays[,holiday[,...]]])

return: mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
param: mixed $startDate Excel date serial value (float), PHP date timestamp (integer),
param: int $endDays The number of nonweekend and nonholiday days before or after
param: mixed $dateArgs

DAYOFMONTH($dateValue = 1)   X-Ref
DAYOFMONTH.

Returns the day of the month, for a specified date. The day is given as an integer
ranging from 1 to 31.

Excel Function:
DAY(dateValue)

return: int|string Day of the month
param: mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),

WEEKDAY($dateValue = 1, $style = 1)   X-Ref
WEEKDAY.

Returns the day of the week for a specified date. The day is given as an integer
ranging from 0 to 7 (dependent on the requested style).

Excel Function:
WEEKDAY(dateValue[,style])

return: int|string Day of the week value
param: float|int|string $dateValue Excel date serial value (float), PHP date timestamp (integer),
param: int $style A number that determines the type of return value

WEEKNUM($dateValue = 1, $method = self::STARTWEEK_SUNDAY)   X-Ref
WEEKNUM.

Returns the week of the year for a specified date.
The WEEKNUM function considers the week containing January 1 to be the first week of the year.
However, there is a European standard that defines the first week as the one with the majority
of days (four or more) falling in the new year. This means that for years in which there are
three days or less in the first week of January, the WEEKNUM function returns week numbers
that are incorrect according to the European standard.

Excel Function:
WEEKNUM(dateValue[,style])

return: int|string Week Number
param: mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
param: int $method Week begins on Sunday or Monday

ISOWEEKNUM($dateValue = 1)   X-Ref
ISOWEEKNUM.

Returns the ISO 8601 week number of the year for a specified date.

Excel Function:
ISOWEEKNUM(dateValue)

return: int|string Week Number
param: mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),

MONTHOFYEAR($dateValue = 1)   X-Ref
MONTHOFYEAR.

Returns the month of a date represented by a serial number.
The month is given as an integer, ranging from 1 (January) to 12 (December).

Excel Function:
MONTH(dateValue)

return: int|string Month of the year
param: mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),

YEAR($dateValue = 1)   X-Ref
YEAR.

Returns the year corresponding to a date.
The year is returned as an integer in the range 1900-9999.

Excel Function:
YEAR(dateValue)

return: int|string Year
param: mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),

HOUROFDAY($timeValue = 0)   X-Ref
HOUROFDAY.

Returns the hour of a time value.
The hour is given as an integer, ranging from 0 (12:00 A.M.) to 23 (11:00 P.M.).

Excel Function:
HOUR(timeValue)

return: int|string Hour
param: mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),

MINUTE($timeValue = 0)   X-Ref
MINUTE.

Returns the minutes of a time value.
The minute is given as an integer, ranging from 0 to 59.

Excel Function:
MINUTE(timeValue)

return: int|string Minute
param: mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),

SECOND($timeValue = 0)   X-Ref
SECOND.

Returns the seconds of a time value.
The second is given as an integer in the range 0 (zero) to 59.

Excel Function:
SECOND(timeValue)

return: int|string Second
param: mixed $timeValue Excel date serial value (float), PHP date timestamp (integer),

EDATE($dateValue = 1, $adjustmentMonths = 0)   X-Ref
EDATE.

Returns the serial number that represents the date that is the indicated number of months
before or after a specified date (the start_date).
Use EDATE to calculate maturity dates or due dates that fall on the same day of the month
as the date of issue.

Excel Function:
EDATE(dateValue,adjustmentMonths)

return: mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
param: mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
param: int $adjustmentMonths The number of months before or after start_date.

EOMONTH($dateValue = 1, $adjustmentMonths = 0)   X-Ref
EOMONTH.

Returns the date value for the last day of the month that is the indicated number of months
before or after start_date.
Use EOMONTH to calculate maturity dates or due dates that fall on the last day of the month.

Excel Function:
EOMONTH(dateValue,adjustmentMonths)

return: mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
param: mixed $dateValue Excel date serial value (float), PHP date timestamp (integer),
param: int $adjustmentMonths The number of months before or after start_date.