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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:11:01+00:00 2026-06-15T03:11:01+00:00

I have a variable ($date) holding the start date of an event which is

  • 0

I have a variable ($date) holding the start date of an event which is in this format:

 2012-11-20 (YYYY-M-D)

And I have another variable ($duration) holding a number e.g ‘3’ which is number of days or duration of the event. How can i increment the day in the date variable by the duration variable and then display the event date in this format

 20th - 23th November

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-06-15T03:11:03+00:00Added an answer on June 15, 2026 at 3:11 am

    Try this:

    echo date('F d Y');
    

    See php date() for more details

    If you have 2012-11-20 in a variable, you can do this:

    $date = '2012-11-20';
    echo date('F d Y', strtotime($date));
    //=> November 20 2012
    

    Two things to consider:

    1. If you don’t have control over the date, you might want to take extra precaution using strtotime(). If you give strtotime() an invalid date string, it will return false
    2. Every call to a date/time function will generate a E_NOTICE if the time zone is not valid, and/or a E_STRICT or E_WARNING message if using the system settings or the TZ environment variable. See also date_default_timezone_set()

    A more robust solution:

    // date input
    $date = '2012-11-20';
    
    // set timezone
    date_default_timezone_set('America/Chicago');
    
    // validate date
    if ( ($time=strtotime($date)) === false ) {
        throw new Exception("invalid date given: {$date}");
    }
    
    // output
    echo date('F d Y', $time);
    

    EDIT

    You updated your question asking how to get a date range. For this, I’d recommend the following:

    // input
    $date = '2012-11-20';
    $duration = 3;
    
    // set timezone
    date_default_timezone_set('America/Chicago');
    
    // parse date
    try {
    
        // init range
        $start = new DateTime($date);
        $end = clone $start;
    
        // modify end date based on $duration
        $end->modify(sprintf("+%d days", $duration));
        
        // output range
        echo $start->format('jS') . ' - ' . $end->format('jS F Y');
    
        //=> 20th - 23rd November 2012
    
    }
    catch (Exception $e) {
        die($e->getMessage());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable called $date with a date format like 2012-01-30. On the
I have a date variable, stored as a String in the 'YYYY-mm-dd' format. What
I have an variable which holds a date in UK format, ie 250711 which
I have a variable called $effectiveDate containing the date 2012-03-26 . I am trying
I have a date variable with the format 2008 12 29 to have it
I have this variable: {{ video.pub_date }} which outputs: May 16, 2011, 2:03 p.m.
I have a date in the format: Thu- Mar 22 2012 .Its is obtained
I have a variable called @status which I set before this select statement: Select
I have a date variable which stores date like: $date = 20100201 //2010, Feb,
I have a variable of type Date. I get this date by using a

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.