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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:06:11+00:00 2026-06-13T23:06:11+00:00

I am trying use strtotime and date functions within a class to add a

  • 0

I am trying use strtotime and date functions within a class to add a number of days to a date consisting of 3 post variables, $month,$day,$year and I don’t know what i’m doing wrong. The date is submitted from a form generated by a function and passed to strtotime.

<?php
//Set vars
$month=$_POST['month'];
$day=$_POST['day'];
$year=$_POST['year'];

//Initalize class
$init=new Some_Class();
$init->setVars($month,$day,$year);

class Some_Class{

    private $someVar;
    private $month;
    private $day;
    private $year;

    public function setVars($var1,$var2,$var3) {
        $this->month=$var1;
        $this->day=$var2;  
        $this->year=$var3;
    }

    function __construct() { 

    }


    function setDate(){
        $start=date("Y")-50;
        $end=date("Y"); 

        $months=array('','January','February','March','April','May',
        'June','July','August', 'September','October','November','December');

        // Month dropdown
        $this->someVar='<select name="month">';

        for($i=1;$i<=12;$i++){
           $this->someVar.="<option value='".str_pad($i, 2, '0', STR_PAD_LEFT)."'>$months[$i]</option>";
        }
        $this->someVar.="</select> ";

        // Day dropdown
        $this->someVar.='<select name="day">';
        for($i=1;$i<=31;$i++){
           $this->someVar.="<option $selected value='".str_pad($i, 2, '0', STR_PAD_LEFT)."'>$i</option>";
        }
        $this->someVar.="</select> ";

        // Year dropdown
        $this->someVar.='<select name="year">';

        for($i=$start;$i<=$end;$i++){      
          $this->someVar.="<option value='$i'>$i</option>";
        }
        $this->someVar.="</select> ";

        return $this->someVar;
    }

    function setDays(){
        $this->someVar['date']=strtotime(implode('-', array($this->year,$this->month,$this->day)));
        $this->someVar['new_date']=strtotime('+42 day',$this->someVar['date']);
        return $this->someVar;  
    }
}

$setDate=$init->setDate();?>
<form action="<?php $_SERVER['REQUEST_URI'];?>" method="post">

  <?php echo $setDate;?>

  <input type="submit" value="submit" name="Submit"/> 
</form>
<?php 
if(isset($month,$day,$year)){
    $setDays=$init->setDays();
    echo date('M d, Y',$setDays['new_date']);
}
?>

If I print the post variables, I can confirm they are being sent, but I can’t quite figure out why i’m not getting return data from setDays().

Any ideas?

EDIT:

function setDays() {
        $this->someVar = array();
        $this->someVar['date']=strtotime(implode('-', array($this->year,$this->month,$this->day)));
        $this->someVar['new_date']=strtotime("+42 day",$this->someVar['date']);
        return $this->someVar;  
    }
  • 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-13T23:06:11+00:00Added an answer on June 13, 2026 at 11:06 pm

    You should try this:

    $this->someVar['date']=strtotime(implode('-', array($this->year,$this->month,$this->day)));
    $this->someVar['new_date']=$this->someVar['date'] + 42 * 24 * 60 * 60;
    

    As I know, strtotime() can be used for adding a number of days like this:

    $date = strtotime('Y-m-d', time() . " +42 day");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use strtotime to convert the following date: 07/09/2009 17:01:27 It's the
I was trying use a set of filter functions to run the appropriate routine,
I'm trying to use rails 3.2 helpers inside a prawn class, but rails throws:
I am trying to get the date of the previous month with python. Here
I'm trying to use the Google Calendar API in my own Java class. Unfortunately,
I'm trying to use strtotime() to respond to a button click to advance -1
I am trying to use strptime(buf, &pattern,&result) to convert char[] containing date into tm
I'm trying to format a date with a day without the leading zero with
i'm trying use facebook API to upload photo in my fan page. I downloaded
I am trying use gem tire to search in my application. I have tables

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.