-2

Possible Duplicate:
Format mysql datetime with php

Well.. I have stored date(c) in Mysql DB and the data type i used in varchar. So it is stored in format 2012-07-01T22:03:02+05:30 . well it kinda look difficult to read.

can anyone help me how to convert it into something like July 1,2012 at 10:03 PM

Community
  • 1
  • 1
  • for the day you could just use a substring and slice it to an array on `-`. – 11684 Jul 01 '12 at 16:59
  • It's not really a duplicate because Prakash seems to want to reformat a regular varchar string - but this problem would definitely be better solved by using a datetime or timestamp field. – Lack Jul 01 '12 at 17:06

3 Answers3

2

php.net/date php.net/strtotime

date( "F d, Y \a\t g:i a", strtotime( $databaseValue ) );
phpmeh
  • 1,752
  • 2
  • 22
  • 41
1

You can still use MySQL date functions - mysql will implicitly cast them to date.

Say you have a table bla, and a field "mydate" of varchar, then just use the following SQL:

select date_format(mydate, '%M %e, %Y at %l:%i %p') as my_formatted_date from bla
disjunction
  • 646
  • 5
  • 8
0

As of PHP 5.3:

$dateMySQL = '2012-07-01T22:03:02+05:30';
$inputFormat = 'Y-m-d\TH:i:sP';
$outputFormat = 'F j,Y \a\t h:i A';
$date = DateTime::createFromFormat($inputFormat, $dateMySQL);
echo $date->format($outputFormat);

which will print "July 1,2012 at 10:03 PM".

Michael Besteck
  • 2,415
  • 18
  • 10