-3

I have code like:

$value = \Carbon\Carbon::createFromFormat('Y-m-d', $value)->format('m/d/Y');

and function format return string, I want to set format but return Carbon object, something like:

$value = \Carbon\Carbon::createFromFormat('Y-m-d', $value)->formatReturnObject('m/d/Y');
Machavity
  • 30,841
  • 27
  • 92
  • 100
fico7489
  • 7,931
  • 7
  • 55
  • 89
  • oh my good I get 2 minuses but question is very good, you can see my solution on answer.... – fico7489 Jun 17 '16 at 08:03
  • Obviously it isn't a good question if your found the answer yourself quickly, you're suppose to be doing your own research first. – Epodax Jun 17 '16 at 08:05
  • I was researching 1 hour and sudenly find a solution. stackoverflow was my last option. – fico7489 Jun 17 '16 at 08:07
  • I have 45 question, some my stupid question have 5 votes up, I think this is my best question and this one have 3 votes down... – fico7489 Jun 17 '16 at 08:09
  • I think your question is voted down, because you didn't write clearly what you are trying to achieve. **I want to set format but return Carbon object** is not very clear to me at least. – henrik Jun 17 '16 at 09:11

1 Answers1

0

I found solution quickly :

$birthday= \Carbon\Carbon::createFromFormat('Y-m-d', $birthday);
$birthday->setToStringFormat('m/d/Y');
return $birthday;

If I run this :

echo $birthday;
print_r($birthday);

Output is:

06/17/1988
Carbon\Carbon Object
(
    [date] => 1988-06-17 07:55:58.000000
    [timezone_type] => 3
    [timezone] => UTC
)
fico7489
  • 7,931
  • 7
  • 55
  • 89