php date->foramt() return object instead of string

97 views Asked by At

I want to output a date object as string using ->format() but when i return the function php automatically convert it to string? how do i prevent that?

function setPassword($currOrder) {

            $checkInDate = $currOrder->checkInDate; // return date object 
            $checkIndate = $checkInDate->format('j/m/Y'); 
            print_r(gettype($checkIndate)); // output string

            return $checkInDate;
        }

print_r( gettype($thisGuest->setPassword($thisOrder)) );  // return object
1

There are 1 answers

0
Moritz On BEST ANSWER

In this case the problem is caused becaus variables are case-sensitive, so $checkIndate and $checkInDate are two different variables. Correct this and you should be fine.