Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 400 and 401]

   1  <?php
   2  
   3  namespace PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel;
   4  
   5  use DateTimeImmutable;
   6  use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
   7  
   8  class Current
   9  {
  10      /**
  11       * DATENOW.
  12       *
  13       * Returns the current date.
  14       * The NOW function is useful when you need to display the current date and time on a worksheet or
  15       * calculate a value based on the current date and time, and have that value updated each time you
  16       * open the worksheet.
  17       *
  18       * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
  19       * and time format of your regional settings. PhpSpreadsheet does not change cell formatting in this way.
  20       *
  21       * Excel Function:
  22       *        TODAY()
  23       *
  24       * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
  25       *                        depending on the value of the ReturnDateType flag
  26       */
  27      public static function today()
  28      {
  29          $dti = new DateTimeImmutable();
  30          $dateArray = Helpers::dateParse($dti->format('c'));
  31  
  32          return Helpers::dateParseSucceeded($dateArray) ? Helpers::returnIn3FormatsArray($dateArray, true) : ExcelError::VALUE();
  33      }
  34  
  35      /**
  36       * DATETIMENOW.
  37       *
  38       * Returns the current date and time.
  39       * The NOW function is useful when you need to display the current date and time on a worksheet or
  40       * calculate a value based on the current date and time, and have that value updated each time you
  41       * open the worksheet.
  42       *
  43       * NOTE: When used in a Cell Formula, MS Excel changes the cell format so that it matches the date
  44       * and time format of your regional settings. PhpSpreadsheet does not change cell formatting in this way.
  45       *
  46       * Excel Function:
  47       *        NOW()
  48       *
  49       * @return mixed Excel date/time serial value, PHP date/time serial value or PHP date/time object,
  50       *                        depending on the value of the ReturnDateType flag
  51       */
  52      public static function now()
  53      {
  54          $dti = new DateTimeImmutable();
  55          $dateArray = Helpers::dateParse($dti->format('c'));
  56  
  57          return Helpers::dateParseSucceeded($dateArray) ? Helpers::returnIn3FormatsArray($dateArray) : ExcelError::VALUE();
  58      }
  59  }