Posted By

robnilas on 01/21/17


Tagged


Versions (?)

How do I show contents based on time and date?


 / Published in: PHP
 

  1. date_default_timezone_set("America/New_York");
  2.  
  3. $exp_date = new DateTime("2009-07-20", new DateTimeZone("America/Los_Angeles"));
  4. $exp_date2 = new DateTime("2009-07-27", new DateTimeZone("America/Los_Angeles"));
  5. $today = new DateTime();
  6. if($today < $exp_date) {
  7. /*...*/
  8. } elseif($today < $exp_date2) {
  9. /*...*/
  10. } else {
  11. /*...*/
  12. }
  13.  
  14. $exp_date = new DateTime("2009-07-20", new DateTimeZone("America/Los_Angeles"));
  15. $exp_date2 = new DateTime("2009-07-27", new DateTimeZone("America/Los_Angeles"));
  16. $today = new DateTime();
  17. if($today < $exp_date) {
  18. /*...*/
  19. } elseif($today < $exp_date2) {
  20. /*...*/
  21. } else {
  22. /*...*/
  23. }
  24.  
  25. $ny = new datetime('2015-02-11 05:55:00', new DateTimeZone('America/New_York'));
  26. $la = new datetime('2015-02-11 02:55:00', new DateTimeZone('America/Los_Angeles'));
  27. var_dump($ny == $la); // bool(true)

Report this snippet  

You need to login to post a comment.