0

I want to convert my date from GMT to simple Date format , i look around on many questions and answers on this site but not succeed.

I have Date

$date = '2010-12-01T02:00:00:000-0500';

and I want to convert this date to 12-01-2010 , i already tried with the date('d-m-Y',strtotime($date)); but it not work here.

Thanks in Advance.

Hardy Mathew
  • 684
  • 1
  • 6
  • 22
  • hi use carbon package laravel already using this package to handle date http://carbon.nesbot.com/ check this tutorial for more reference https://laracasts.com/series/laravel-5-fundamentals/episodes/11 – umefarooq May 01 '15 at 19:20
  • @umefarooq I want o use this in View is there any way for laravel5? I already check with http://stackoverflow.com/questions/27181009/use-carbon-on-views-laravel – Hardy Mathew May 01 '15 at 19:41
  • if its is coming from database check laracast tutorial link already there you can create carbon object in model and later you can use it in view – umefarooq May 01 '15 at 19:48
  • its not for the database , it's from the api – Hardy Mathew May 01 '15 at 19:49

1 Answers1

1

This should work for you:

Just use DateTime::createFromFormat() to create a DateTime object out of your formatted date, like this:

$date = "2010-12-01T02:00:00:000-0500";
$date = DateTime::createFromFormat("Y-m-d\TH:i:s:uP", $date);
echo $date->format("m-d-Y");

output:

12-01-2010
Rizier123
  • 58,877
  • 16
  • 101
  • 156