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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:40:56+00:00 2026-06-12T16:40:56+00:00

I want to compute the next Xth day in the calendar. For example today

  • 0

I want to compute the next Xth day in the calendar.

For example today is 2012-10-08. if X=25 i want it to return 2012-10-25 but if X=06 i want 2012-11-06. If the month doesn’t have the required X days, it must return the last day of the month (if i’m looking for the 30th of february for example, it must return 28 or 29 if leap year)

It seems simple enough but I get caught by all the special cases (last month of the year, 28-31 day months, etc).

  • 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-12T16:40:58+00:00Added an answer on June 12, 2026 at 4:40 pm

    You can use strtotime() and t:

    $x = 5;                   // given day
    if(date('t') < $x){       // check if last day of the month is lower then given day
        $x = date('t');       // if yes, modify $x to last day of the month
    }
    
    $month = date('m');       // current month
    if(date('d') >= $x){      // if $x day is now or has passed
        $month = $month+1;    // increase month by 1
    }
    
    $year = date('Y');        // current year
    if($month > 12){          // if $month is greater than 12 as a result from previous if
        $year = date('Y')+1;  // increase year
        $month = 1;           // set month to January
    }
    
    if(date('t', strtotime($year.'-'.$month.'-01')) < $x){       // check if last day of the new month is lower then given day
        $x = date('t', strtotime($year.'-'.$month.'-01'));       // if yes, modify $x to last day of the new month
    }
    
    $date = date('d F Y', strtotime($year.'-'.$month.'-'.$x));
    // 05 November 2012
    

    HERE is a nice tutorial.

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

Sidebar

Related Questions

I have a 3-dimensial matrix W of size 160x170x18 and I want to compute
I have a list of AWT rectangles. I want to compute the union of
We have an intern starting next week. He has a Computer Science degree but
I have a sequence of real numbers and I want to compute the FFT
I want to have the HighChart update the series by added the next data
I want to compute the time 4 hours later during the DST transition, either
For use in a rigid body simulation, I want to compute the mass and
I want to ask how to add a computed column in BIRT that compute
I am using CoreGraphics to draw a quadratic bezier but want to computer the
May be it sound dumb but if I want some computed value from other

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.