Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $timestamp=1330581600
- e.g.
- $beginOfDay = Start of Timestamp's Day
- $endOfDay = End of Timestamp's Day
- $endOfDay = $timestamp + (60 * 60 * 23);
- $beginOfDay = strtotime("midnight", $timestamp);
- $endOfDay = strtotime("tomorrow", $beginOfDay) - 1;
- $dtNow = new DateTime();
- // Set a non-default timezone if needed
- $dtNow->setTimezone(new DateTimeZone('Pacific/Chatham'));
- $dtNow->setTimestamp($timestamp);
- $beginOfDay = clone $dtNow;
- // Go to midnight. ->modify('midnight') does not do this for some reason
- $beginOfDay->modify('today');
- $endOfDay = clone $beginOfDay;
- $endOfDay->modify('tomorrow');
- // adjust from the next day to the end of the day, per original question
- $endOfDay->modify('1 second ago');
- var_dump(
- array(
- 'time ' => $dtNow->format('Y-m-d H:i:s e'),
- 'start' => $beginOfDay->format('Y-m-d H:i:s e'),
- 'end ' => $endOfDay->format('Y-m-d H:i:s e'),
- )
- );
- $beginOfDay = DateTime::createFromFormat('Y-m-d H:i:s', (new DateTime())->setTimestamp($timestamp)->format('Y-m-d 00:00:00'))->getTimestamp();
- $endOfDay = DateTime::createFromFormat('Y-m-d H:i:s', (new DateTime())->setTimestamp($timestamp)->format('Y-m-d 23:59:59'))->getTimestamp();
- $dateTimeObject = new DateTime();
- $dateTimeObject->setTimestamp($timestamp);
- $beginOfDayString = $dateTimeObject->format('Y-m-d 00:00:00');
- $beginOfDayObject = DateTime::createFromFormat('Y-m-d H:i:s', $beginOfDayString);
- $beginOfDay = $beginOfDayObject->getTimestamp();
- $endOfDayObject = clone $beginOfDayOject(); // Cloning because add() and sub() modify the object
- $endOfDayObject->add(new DateInterval('P1D'))->sub(new DateInterval('PT1S'));
- $endOfDay = $endOfDayOject->getTimestamp();
- $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();
- list($y,$m,$d) = explode('-', date('Y-m-d', $ts));
- $start = mktime(0,0,0,$m,$d,$y);
- $end = mktime(0,0,0,$m,$d+1,$y);
- $start_of_day = time() - 86400 + (time() % 86400);
- $end_of_day = $start_of_day + 86400;
- $stamp = mktime(0, 0, 0);
- echo date('m-d-Y H:i:s',$stamp);
- <?php
- $date = "2015-04-12 09:20:00";
- $midnight = strtotime("midnight", strtotime($date));
- $now = strtotime($date);
- $diff = $now - $midnight;
- echo $diff;
- ?>
- <?php
- $midnight = strtotime("midnight");
- $now = date('U');
- $diff = $now - $midnight;
- echo $diff;
- ?>
- $start_of_day = floor (time() / 86400) * 86400;
- $end_of_day = ceil (time() / 86400) * 86400;
- $start_of_day = floor (time() / 86400) * 86400;
- $end_of_day = $start_of_day + 86400;
- $today = date('Y-m-d 00:00:00');
Add Comment
Please, Sign In to add comment