Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

(no description)

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

Defines 1 class

DateTime:: (28 methods):
  isLeapYear()
  dateDiff360()
  getDateValue()
  getTimeValue()
  adjustDateByMonths()
  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.

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

dateDiff360($startDay, $startMonth, $startYear, $endDay, $endMonth, $endYear, $methodUS)   X-Ref
Return the number of days between two dates based on a 360 day calendar.

param: int $startDay Day of month of the start date
param: int $startMonth Month of the start date
param: int $startYear Year of the start date
param: int $endDay Day of month of the start date
param: int $endMonth Month of the start date
param: int $endYear Year of the start date
param: bool $methodUS Whether to use the US method or the European method of calculation
return: int Number of days between the start date and the end date

getDateValue($dateValue)   X-Ref
getDateValue.

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

getTimeValue($timeValue)   X-Ref
No description

adjustDateByMonths($dateValue = 0, $adjustmentMonths = 0)   X-Ref
No description

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)

PhpSpreadsheet is a lot more forgiving than MS Excel when passing non numeric values to this function.
A Month name or abbreviation (English only at this point) such as 'January' or 'Jan' will still be accepted,
as will a day value with a suffix (e.g. '21st' rather than simply 21); again only English language.

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
return: mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,

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)

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.
return: mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,

DATEVALUE($dateValue = 1)   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)

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

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)

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

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

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
return: int|string Interval between the dates

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

Returns the number of days between two dates

Excel Function:
DAYS(endDate, startDate)

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

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])

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
return: int|string Number of days between start date and end date

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])

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
return: float fraction of the year

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[,...]]])

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

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[,...]]])

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
return: mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,

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)

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

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])

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

WEEKNUM($dateValue = 1, $method = 1)   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])

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

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

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

Excel Function:
ISOWEEKNUM(dateValue)

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

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)

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

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)

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

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)

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

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)

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

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)

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

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)

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

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)

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