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

  • Home
  • SEARCH
  • 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 575735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:58:20+00:00 2026-05-13T13:58:20+00:00

I need to add working hours to a timestamp. Working hours are from 8am

  • 0

I need to add working hours to a timestamp. Working hours are from 8am to 6pm. Lets say we have 2pm and I have to add 6 hours. Result should be 10am… any guesses?

Thanks.

  • 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-13T13:58:21+00:00Added an answer on May 13, 2026 at 1:58 pm

    Try this bad boy.

    You can specify whether to include weekends as working days, etc. Doesn’t take into account holidays.

    <?php
    
    function addWorkingHours($timestamp, $hoursToAdd, $skipWeekends = false)
    {
        // Set constants
        $dayStart = 8;
        $dayEnd = 16;
    
        // For every hour to add
        for($i = 0; $i < $hoursToAdd; $i++)
        {
            // Add the hour
            $timestamp += 3600;
    
            // If the time is between 1800 and 0800
            if ((date('G', $timestamp) >= $dayEnd && date('i', $timestamp) >= 0 && date('s', $timestamp) > 0) || (date('G', $timestamp) < $dayStart))
            {
                // If on an evening
                if (date('G', $timestamp) >= $dayEnd)
                {
                    // Skip to following morning at 08XX
                    $timestamp += 3600 * ((24 - date('G', $timestamp)) + $dayStart);
                }
                // If on a morning
                else
                {
                    // Skip forward to 08XX
                    $timestamp += 3600 * ($dayStart - date('G', $timestamp));
                }
            }
    
            // If the time is on a weekend
            if ($skipWeekends && (date('N', $timestamp) == 6 || date('N', $timestamp) == 7))
            {
                // Skip to Monday
                $timestamp += 3600 * (24 * (8 - date('N', $timestamp)));
            }
        }
    
        // Return
        return $timestamp;
    }
    
    // Usage
    $timestamp = time();
    $timestamp = addWorkingHours($timestamp, 6);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a need to add business reporting for an application I am working
I need to add DVD writing functionality to an application I'm working on. However
I'm working on a WordPress template and need to add a hyperlink to the
I am working on some code were I need to add a Node into
I am working on the project and now I need to add a foreign
I need to add some appointments from a legacy system into Dynamics. During the
Well basically I'm now working on contact form, and I need to add two
I am currently working on a c# project where I need to add to
I'm working on a site that lets users add calendar entries, on the main
Working on a project where I need to add points to an array. Here

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.