1

Possible Duplicate:
Format mysql datetime with php

I take and store a date into a mysql database. It displays like this:

2011-03-17 17:49:49

But I want it to show like this instead:

Thur 17 March 2011 5:49 PM

Community
  • 1
  • 1
Sachin
  • 11
  • 1
  • 2
  • 1
    There must be some Date Formatting function in PHP. Isn't it? – Nishant Mar 18 '11 at 04:43
  • use time() so its a unixtime stamp in the db, then convert it when you display it – Lawrence Cherone Mar 18 '11 at 04:56
  • Possible dupes : http://stackoverflow.com/questions/1535246/php-format-date-from-database http://stackoverflow.com/questions/136782/format-mysql-datetime-with-php http://stackoverflow.com/questions/3654101/format-a-date-string-in-php http://stackoverflow.com/questions/2167916/php-convert-one-date-into-another-date-format – gideon Mar 18 '11 at 05:08

8 Answers8

0

use date() in PHP: http://us.php.net/manual/en/function.date.php

or

format your output in mysql: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

bensiu
  • 24,660
  • 56
  • 77
  • 117
0

Convert it into a timestamp with strtotime(), and then format it with date() in PHP.

Keith Gaughan
  • 21,367
  • 3
  • 32
  • 30
0

You should do formatting with date function.

date('D d F Y g:i a', strtotime($date));

Refer to manual for more.

S L
  • 14,262
  • 17
  • 77
  • 116
0

Use the below function

date("D j F, Y, g:i a");

Vijay
  • 5,331
  • 10
  • 54
  • 88
0

$today = date(”F j, Y, g:i a”); -> February 5, 2010, 6:20 pm refer these links it may help u link1 link2 link3

Akshatha
  • 599
  • 2
  • 10
  • 26
0
$time = '2011-03-17 17:49:49';

$date = new DateTime($time);

echo $date->format('D j F Y g:i A'); // Thu 17 March 2011 5:49 PM

Note that in your example, you have Thur and not Thu as per my output. PHP doesn't have any native character to represent this, but you could do...

$time = '2011-03-17 17:49:49';

$date = new DateTime($time);

echo substr($date->format('l'), 0, 4) . $date->format(' j F Y g:i A'); 
// Thur 17 March 2011 5:49 PM
alex
  • 479,566
  • 201
  • 878
  • 984
0
$given_date = '2011-03-17 17:49:49';

echo $ur_date     = date('D j F Y g:i:s A',strtotime($given_date));

http://www.php.net/manual/en/datetime.createfromformat.php

Angelin Nadar
  • 8,944
  • 10
  • 43
  • 53
0

best to store dates in the db as unix time stamp then when there outputted use something like this to display it how you want

<?php
// echo date ( "F j, Y, g:i a", timestamp );

// Assuming today is: March 10th, 2001, 5:16:18 pm

$today = date("F j, Y, g:i a");                 // March 10, 2001, 5:16 pm
$today = date("m.d.y");                         // 03.10.01
$today = date("j, n, Y");                       // 10, 3, 2001
$today = date("Ymd");                           // 20010310
$today = date('h-i-s, j-m-y, it is w Day z ');  // 05-16-17, 10-03-01, 1631 1618 6 Fripm01
$today = date('\i\t \i\s \t\h\e jS \d\a\y.');   // It is the 10th day.
$today = date("D M j G:i:s T Y");               // Sat Mar 10 15:16:08 MST 2001
$today = date('H:m:s \m \i\s\ \m\o\n\t\h');     // 17:03:17 m is month
$today = date("H:i:s");                         // 17:16:17
?> 
Lawrence Cherone
  • 46,049
  • 7
  • 62
  • 106