Guest User

Untitled

a guest
Jun 21st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. $timestamp=1330581600
  2.  
  3. e.g.
  4. $beginOfDay = Start of Timestamp's Day
  5. $endOfDay = End of Timestamp's Day
  6.  
  7. $endOfDay = $timestamp + (60 * 60 * 23);
  8.  
  9. $beginOfDay = strtotime("midnight", $timestamp);
  10. $endOfDay = strtotime("tomorrow", $beginOfDay) - 1;
  11.  
  12. $dtNow = new DateTime();
  13. // Set a non-default timezone if needed
  14. $dtNow->setTimezone(new DateTimeZone('Pacific/Chatham'));
  15. $dtNow->setTimestamp($timestamp);
  16.  
  17. $beginOfDay = clone $dtNow;
  18.  
  19. // Go to midnight. ->modify('midnight') does not do this for some reason
  20. $beginOfDay->modify('today');
  21.  
  22. $endOfDay = clone $beginOfDay;
  23. $endOfDay->modify('tomorrow');
  24. // adjust from the next day to the end of the day, per original question
  25. $endOfDay->modify('1 second ago');
  26.  
  27. var_dump(
  28. array(
  29. 'time ' => $dtNow->format('Y-m-d H:i:s e'),
  30. 'start' => $beginOfDay->format('Y-m-d H:i:s e'),
  31. 'end ' => $endOfDay->format('Y-m-d H:i:s e'),
  32. )
  33. );
  34.  
  35. $beginOfDay = DateTime::createFromFormat('Y-m-d H:i:s', (new DateTime())->setTimestamp($timestamp)->format('Y-m-d 00:00:00'))->getTimestamp();
  36. $endOfDay = DateTime::createFromFormat('Y-m-d H:i:s', (new DateTime())->setTimestamp($timestamp)->format('Y-m-d 23:59:59'))->getTimestamp();
  37.  
  38. $dateTimeObject = new DateTime();
  39. $dateTimeObject->setTimestamp($timestamp);
  40. $beginOfDayString = $dateTimeObject->format('Y-m-d 00:00:00');
  41. $beginOfDayObject = DateTime::createFromFormat('Y-m-d H:i:s', $beginOfDayString);
  42. $beginOfDay = $beginOfDayObject->getTimestamp();
  43.  
  44. $endOfDayObject = clone $beginOfDayOject(); // Cloning because add() and sub() modify the object
  45. $endOfDayObject->add(new DateInterval('P1D'))->sub(new DateInterval('PT1S'));
  46. $endOfDay = $endOfDayOject->getTimestamp();
  47.  
  48. $beginOfDay = DateTime::createFromFormat('Y-m-d H:i:s O', (new DateTime())->setTimezone(new DateTimeZone('America/Los_Angeles'))->setTimestamp($timestamp)->format('Y-m-d 00:00:00 O'))->getTimestamp();
  49.  
  50. list($y,$m,$d) = explode('-', date('Y-m-d', $ts));
  51. $start = mktime(0,0,0,$m,$d,$y);
  52. $end = mktime(0,0,0,$m,$d+1,$y);
  53.  
  54. $start_of_day = time() - 86400 + (time() % 86400);
  55. $end_of_day = $start_of_day + 86400;
  56.  
  57. $stamp = mktime(0, 0, 0);
  58. echo date('m-d-Y H:i:s',$stamp);
  59.  
  60. <?php
  61. $date = "2015-04-12 09:20:00";
  62.  
  63. $midnight = strtotime("midnight", strtotime($date));
  64. $now = strtotime($date);
  65.  
  66. $diff = $now - $midnight;
  67. echo $diff;
  68. ?>
  69.  
  70. <?php
  71. $midnight = strtotime("midnight");
  72. $now = date('U');
  73.  
  74. $diff = $now - $midnight;
  75. echo $diff;
  76. ?>
  77.  
  78. $start_of_day = floor (time() / 86400) * 86400;
  79. $end_of_day = ceil (time() / 86400) * 86400;
  80.  
  81. $start_of_day = floor (time() / 86400) * 86400;
  82. $end_of_day = $start_of_day + 86400;
  83.  
  84. $today = date('Y-m-d 00:00:00');
Add Comment
Please, Sign In to add comment