Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7823617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:18:44+00:00 2026-06-02T08:18:44+00:00

I have a Unix timestamp like this: $timestamp=1330581600 How do I get the beginning

  • 0

I have a Unix timestamp like this:

$timestamp=1330581600

How do I get the beginning of the day and the end of the day for that timestamp?

e.g.
$beginOfDay = Start of Timestamp's Day
$endOfDay = End of Timestamp's Day

I tried this:

$endOfDay = $timestamp + (60 * 60 * 23);

But I don’t think it’ll work because the timestamp itself isn’t the exact beginning of the day.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T08:18:45+00:00Added an answer on June 2, 2026 at 8:18 am

    strtotime can be used to to quickly chop off the hour/minutes/seconds

    $beginOfDay = strtotime("today", $timestamp);
    $endOfDay   = strtotime("tomorrow", $beginOfDay) - 1;
    

    DateTime can also be used, though requires a few extra steps to get from a long timestamp

    $dtNow = new DateTime();
    // Set a non-default timezone if needed
    $dtNow->setTimezone(new DateTimeZone('Pacific/Chatham'));
    $dtNow->setTimestamp($timestamp);
    
    $beginOfDay = clone $dtNow;
    $beginOfDay->modify('today');
    
    $endOfDay = clone $beginOfDay;
    $endOfDay->modify('tomorrow');
    // adjust from the start of next day to the end of the day,
    // per original question
    // Decremented the second as a long timestamp rather than the
    // DateTime object, due to oddities around modifying
    // into skipped hours of day-lights-saving.
    $endOfDateTimestamp = $endOfDay->getTimestamp();
    $endOfDay->setTimestamp($endOfDateTimestamp - 1);
    
    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'),
        )
    );
    

    With the addition of extended time in PHP7, there is potential to miss a second if using $now <= $end checking with this.
    Using $now < $nextStart checking would avoid that gap, in addition to the oddities around subtracting seconds and daylight savings in PHP’s time handling.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a unix timestamp that I would like to convert using mysql if
I have a Unix timestamp that I need to get the individual year, month,
I've tried to convert a UNIX Timestamp to todays date time. Like I have
I'd like to get the unix timestamp of the beginning of current (or any
I have a CSV file that looks like this, where time is a UNIX
I have a unix timestamp like this one: 1323668326 . I want to convert
I'd like to a convert unix timestamp I have in a string (ex. 1277722499.82)
I have a fractional epoch timestamp, represented as double , that I would like
How can I use PHP to get a UNIX timestamp like what I get
I have a table that looks like this CREATE TABLE `time_table` ( `id` INT(10)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.