0

Stack Overflow-ers,

I can output the variable $raw_date as 20130216 by simply using echo $raw_date;, however I would like to be able to output either 16/02 or 16/02/2013 from the same $raw_date variable.

Is this possible, and if so how?

Thanks, Jamie

Jamie
  • 332
  • 1
  • 3
  • 14
  • 2
    Yes it is. what have you tried? – sachleen Feb 16 '13 at 17:49
  • 1
    string splitting isn't the answer you want; you don't have to do date formatting manually -- PHP has much more powerful tools available for you. If you must do it manually (or for other similar tasks), look up the `str_split()` function, but with such an obvious function name to look for, I'm a bit worried that you didn't manage to find it without asking. – Spudley Feb 16 '13 at 17:55

1 Answers1

8
$d = DateTime::createFromFormat('Ymd', $raw_data);
echo $d->format('d/m/Y');
galchen
  • 5,252
  • 3
  • 29
  • 43