bsanneh
bsanneh

Reputation: 521

Want to calculate the end date from the start date given using CjuiDatePicker

I am new to yii framework and i am using the CJUIDatePicker to get a start_date which is inserted to my table. I also have a field called end_date and I want to insert the end_date from the code, e.g. like this:

$this->end_date = $this->start_date + 2Months; // how to do this?

Upvotes: 0

Views: 440

Answers (2)

bsanneh
bsanneh

Reputation: 521

I was able to get it after some more research .Here it is

$currentDate = $this->start_date;//sets the start_date to the variable

$this->end_date= date("Y-m-d", strtotime('+4 year',strtotime($currentDate)));//the end_date is now start_date plus 4 years

thank

Upvotes: 0

Jon
Jon

Reputation: 437396

It depends on what is the format for start_date and end_date. If it's a UNIX timestamp, then the simplest would be:

$this->end_date = strtotime('+2 months', $this->start_date);

If it's something else, the answer depends on what exactly.

Upvotes: 1

Related Questions