Search code examples
phpdateformats

How to put date format in php


I have some php code that calls a date with $modified[$x] that I need formatted to (D, d M Y H:i:s T) for an RSS feed.

the date looks like 20130306 when it currently displays

the time should be 10am

I have been trying to use date_format($date, 'D, d M Y H:i:s'), but I can't get it to work

the array I am trying to format is built with $modified[$x]=$year . $month . $day;


Solution

  • Try:

    date( 'D, d M Y H:i:s T', strtotime( '20130306 10am' ) );
    

    or:

    $date = new DateTime('20130306 10am');
    $date->format('D, d M Y H:i:s T');
    

    Example:

    $modified[$x] = date( 'D, d M Y H:i:s T', strtotime( $year.$month.$day.' 10am' ) );