• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error in Array to string conversion

#21
problem with strtotime.....
try with https://www.php.net/manual/en/datetime.add.php
follow example in the doc
Reply

#22
(06-13-2019, 03:08 AM)hc-innov Wrote: problem with strtotime.....
try with https://www.php.net/manual/en/datetime.add.php
follow example in the doc

i tried like this.
$dob=$this->input->post('dob');
$day_retire=date_add($dob, date_interval_create_from_date_string('60 years'));
$due_date_retire=date_format($day_retire, 'Y-m-d');

then it says
A PHP Error was encountered
Message: date_add() expects parameter 1 to be DateTime, string given
Message: date_format() expects parameter 1 to be DateTimeInterface, boolean given
{"status":true}


$due_date_retire takes the value 0000-00-00
i'm unable to understand this Sad
Reply

#23
(06-13-2019, 03:21 AM)jackey Wrote:
(06-13-2019, 03:08 AM)hc-innov Wrote: problem with strtotime.....
try with https://www.php.net/manual/en/datetime.add.php
follow example in the doc

i tried like this.
$dob=$this->input->post('dob');
$day_retire=date_add($dob, date_interval_create_from_date_string('60 years'));
$due_date_retire=date_format($day_retire, 'Y-m-d');

then it says
A PHP Error was encountered
Message: date_add() expects parameter 1 to be DateTime, string given
Message: date_format() expects parameter 1 to be DateTimeInterface, boolean given
{"status":true}


$due_date_retire takes the value 0000-00-00
i'm unable to understand this Sad


Smile now it works

the correct one is
$dob= date_create($this->input->post('dob'));
$day_retire=date_add($dob, date_interval_create_from_date_string('60 years'));
$due_date_retire=date_format($day_retire, 'Y-m-d');

thank you very much hc-innov for your support
Reply

#24
the good code
PHP Code:
$dob=$this->input->post('dob');
$dob date_create($dob);
//for debug
var_dump($dob);
$day_retire=date_add($dobdate_interval_create_from_date_string('60 years'));
$due_date_retire=date_format($day_retire'Y-m-d');
//for debug
var_dump($due_date_retire);
die(); 
Reply

#25
(06-13-2019, 03:32 AM)hc-innov Wrote: the good code
PHP Code:
$dob=$this->input->post('dob');
$dob date_create($dob);
//for debug
var_dump($dob);
$day_retire=date_add($dobdate_interval_create_from_date_string('60 years'));
$due_date_retire=date_format($day_retire'Y-m-d');
//for debug
var_dump($due_date_retire);
die(); 

once again thank you very much hc-innov for your support
Reply

#26
Happy to help you.
Don't forget, php.net is your friend....
Reply

#27
(06-13-2019, 02:22 AM)jackey Wrote: it works, but it returns  1970-01-01 as $due_date_retire for any dob.
It doesnot add 60 years to dob.
Sad

That's because you forgot to put a space before the +60, as I advised you in the first place.
PHP Code:
$dob $this->input->post('dob');
$due_date_retire date('Y-m-d'strtotime($dob ' +60 years')); 

That really is the only reason why you got 1970-01-01.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.