1

I'm looking to convert a date from one format to another.

This is my current date format:

2011-08-15 15:35:58

and I need to convert it into:

Mon, 15/08/2011 15:35

I can quite easily create this by cutting the last 3 characters from the time and then using str_replace to change '-' into '/' and so on, but I was wondering if there is there is a way to do this automatically using the date() function or something similar. I am also not sure how to generate the day of the week e.g. 'Mon', 'Tues' etc.

Hope someone can help. Thanks.

lukehillonline
  • 2,430
  • 2
  • 32
  • 48

3 Answers3

4

This can be done easily using a combination of date() and strtotime():

$newDate = date('D, d/m/Y H:i', strtotime($oldDate));
Dunhamzzz
  • 14,682
  • 4
  • 50
  • 74
1

Use strtotime and date functions:

$d = strtotime("2011-08-15 15:35:58");

var_dump(date( 'D, d/n/Y H:i',$d));
Robik
  • 6,047
  • 4
  • 31
  • 41
0

This code work fine:

<?

$time = strtotime("2011-08-15 15:35:58");
echo date("D, d/m/y H:m", $time);

But be carefull, strtotime depends on timezone settings.

neworld
  • 7,757
  • 3
  • 39
  • 61