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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:51:44+00:00 2026-06-12T17:51:44+00:00

I have two numbers; dates in Unix Epoch format. Say I have two Unix

  • 0

I have two numbers; dates in Unix Epoch format.

Say I have two Unix Epoch timestamps:

1349422200 = 05/10/2012 08:30
1350489600 = 17/10/2012 17:00

I am able to find out how many days are between the two date/times, no problem.
What I would like to be able to work out is how many of those days are Saturdays or Sundays (Non-Weekdays). I’m sure there has to be an easy way to go about this but I can’t for the life of me figure it out without doing a load of for() loops.

Any help greatly appreciated.

  • 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-12T17:51:45+00:00Added an answer on June 12, 2026 at 5:51 pm

    Be more specific with your definition of weekend. Do you only want to include whole weekends (the entire 48 hour period of saturday and sunday)? Or does any range of time containing midnight on Friday night/Saturday morning count as a weekend? Do half weekends count as half, or do you round to the nearest whole number?

    In any case:

    1. Figure out what comprises a weekend
    2. Find the first and last weekends in your range of time
    3. Find the time difference between them, in days, and divide by 7

    Edit: you’re seeking the exact amount of weekend time, with no rounding.

    First, split the timespan into 3 chunks:

    1. Everything from the beginning of the range up until the first possible Monday morning at midnight
    2. Everything from the end of the previous block up to the last possible Monday morning at midnight
    3. Everything from the end of the previous block to the end of the range

    Then calculate the amount of weekend in each block, and sum them up.

    1. The first block will contain no weekend time if it has a length of zero. If it has a length of 48 hours or less, its weekend time will equal its length. Otherwise, its weekend time will be 48 hours.
    2. The middle block’s weekend time is its duration multiplied by 2/7 (trivial, since by our restrictions on its start and end, it is a whole number of weeks.)
    3. The final block will contain no weekend time if its duration is less than or equal to five days. If its duration is greater than five days, its weekend time will equal its duration minus five days.

    Special cases

    If the block contains no monday midnights, consider the second and third blocks to have a length of zero. Find the beginning and the end of the one weekend inside the block (if it exists) and calculate the overlap.

    If the block contains exactly one monday midnight, consider the first block the time before it, the second block to be of zero length, and the third block the time after it, and calculate as usual.

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

Sidebar

Related Questions

Possible Duplicate: Subtracting dates in PHP I have two Unix timestamps, how can I
Say for example I have a set of dates and a set of numbers
I have two dates: Jun 26 2012 12:13AM and Jul 31 2012 12:54PM I
I have two dates in which i would like to find the number of
I have to subtract two dates and divide it by the number of cells
I have two NSMutabeArrays, one full of numbers, the other full of words. Lets
I have two arrays, the first one contents numbers and the second one use
I have two forms. First one is to decide button numbers by using jslider.
I have a file in which each line contains two numbers. The problem is
In this problem, I have three (identically-structured) lists. Two have all numbers and the

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.