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 6207525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:38:42+00:00 2026-05-24T05:38:42+00:00

What would be a good solution to round a timestamp to the hour? For

  • 0

What would be a good solution to round a timestamp to the hour?

For example, after using date('d.m.y h:m', time()), I get ‘02.08.11 7:07’… Now, from this, I’d like to have the timestamp for 7:00.

How can I achieve that?

  • 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-05-24T05:38:43+00:00Added an answer on May 24, 2026 at 5:38 am

    Update

    After seeing Greg Miller’s “Time Programming Fundamentals” talk about Google’s cctz C++ library, I am dissatisfied with my previous answer.

    Handling time is a very complex topic (even when discounting relativistic effects). We have to honor things like timezones with uneven offsets, daylight saving time, time jumps due to legislation changes or leap seconds and probably many more quirks.
    While many of these have only a local effect in time and space, users of our programs can still be unlucky enough to get affected.

    TL;DR

    It is probably best to rely on underlying functions like in holodoc’s answer to handle the quirks of timezone management.

    Old Answer

    When I remember correctly the timestamp started at exactly 0:00 1.1.1970 so it should suffice to divide it by 3600 (floating) then round/floor/ceil and multiply by 3600 (integer). The division must be floating point for round/ceil to work.

    Sample of rounding:

    round($timestamp/3600)*3600
    7:20 -> 7:00
    7:40 -> 8:00
    

    Sample of flooring:

    floor($timestamp/3600)*3600
    7:20 -> 7:00
    7:40 -> 7:00
    

    Sample of ceiling:

    ceil($timestamp/3600)*3600
    7:20 -> 8:00
    7:40 -> 8:00
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Had anyone experienced that issue before? What would be a good solution? I'm using
I have a solution that contains a good deal of projects, I would like
what, if at all possible, would be a good solution to implement the following
I have looked everywhere and surprisingly can't find a good solution to this! I've
I would like to get from sqlite value that will be different for OS
I have one obviously simple problem, but cannot find good solution, so I would
Which would be a good solution to paginate commits when I have a query
Anything would be good. Exemples, best practices, samples, etc.
Thinking in regards to Sliverlight, I would like to know where would be good
I have some useful wpf buttons to test some functionality. It would be good

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.