RLeisinger
RLeisinger

Reputation: 218

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;

Upvotes: 1

Views: 796

Answers (2)

Danijel
Danijel

Reputation: 12689

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' ) );

Upvotes: 2

Bob The Janitor
Bob The Janitor

Reputation: 20792

try

date_format('D, d M Y H:i:s',$date)

if $date is a string you may need to do

date_format('D, d M Y H:i:s',strtotime($date)) 

Upvotes: 2

Related Questions