1

I have a field in a database labelled "timestamp" that is recording the current_timestamp.

What PHP code do I need to write in order to get the current_timestamp (YYYY-MM-DD HH:MM:SS) to display as something a little more reader friendly, i.e. (April 30, 2012 at 3:45pm)

Murphy1976
  • 1,415
  • 8
  • 40
  • 88

5 Answers5

6

use : date("Y-m-d H:i:s", $current_timestamp);

or for format like April 30, 2012 at 3:45pm use :

date('F j, Y at g:ia', $current_timestamp);
Mouna Cheikhna
  • 38,870
  • 10
  • 48
  • 69
6

Great resource for this: http://php.net/manual/en/function.date.php

$dateTimeVariable = date("F j, Y \a\t g:ia");

This will give you that format of the current time (which seemed to be what you were getting at), otherwise you need to pass the timestamp in after the date format string.

Sean Carruthers
  • 414
  • 2
  • 10
  • won't 't' give the number of days in the month instead of the day indicated by the timestamp? – Jeff Lambert Feb 24 '12 at 20:27
  • Sean, you are the winner of this contest. But for some reason, the "at" in the date("F t, Y at g:ia") is just coming back as the meridiem and day respectively. Any thoughts? – Murphy1976 Feb 24 '12 at 20:32
3

See the documentation for the date function and strtotime function.

date('F j, Y \a\t g:ia', strtotime( $current_time ));
Jeff Lambert
  • 24,395
  • 4
  • 69
  • 96
0
$time = strtotime($DBDataColumn);
strftime('%a, %b %d %Y at %I:%M %p', $time);
Churk
  • 4,556
  • 5
  • 22
  • 37
0

Use the Date object

$date = DateTime::createFromFormat('Y-m-d H:i:s', $timestamp);
echo $date->format("F t, Y at H:i")
Tchoupi
  • 14,560
  • 5
  • 37
  • 71
  • Your lines are good, but people normal not know about class::(acces)funcion :( –  Feb 12 '16 at 15:07