date_modify_basic1.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. --TEST--
  2. Test date_modify() function : basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype : DateTime date_modify ( DateTime $object , string $modify )
  6. * Description: Alter the timestamp of a DateTime object by incrementing or decrementing in a format accepted by strtotime().
  7. * Source code: ext/date/php_date.c
  8. * Alias to functions: public DateTime DateTime::modify()
  9. */
  10. //Set the default time zone
  11. date_default_timezone_set("Europe/London");
  12. echo "*** Testing date_modify() : basic functionality ***\n";
  13. // Create a date object to modify
  14. $datetime = date_create("2009-01-31 14:28:41");
  15. date_modify($datetime, "+1 day");
  16. echo "After modification 1: " . date_format($datetime, "D, d M Y") . "\n";
  17. date_modify($datetime, "+1 week 2 days 4 hours 2 seconds");
  18. echo "After modification 2: " . date_format($datetime, "D, d M Y H:i:s") . "\n";
  19. date_modify($datetime, "next Thursday");
  20. echo "After modification 3: " . date_format($datetime, "D, d M Y") . "\n";
  21. date_modify($datetime, "last Sunday");
  22. echo "After modification 4: " . date_format($datetime, "D, d M Y") . "\n";
  23. ?>
  24. ===DONE===
  25. --EXPECTF--
  26. *** Testing date_modify() : basic functionality ***
  27. After modification 1: Sun, 01 Feb 2009
  28. After modification 2: Tue, 10 Feb 2009 18:28:43
  29. After modification 3: Thu, 12 Feb 2009
  30. After modification 4: Sun, 08 Feb 2009
  31. ===DONE===