0

I have a page that allows users to create and submit posts. In order to determine the time of their post, I used timestamp in mysql.

Here's a sample of one of the timestamps in my data:
2017-05-07 16:12:44.415472

Using php (or javascript if there's actually no other way), how can I make it display something like this: Sunday, May 07, 2017 4:00PM


I also want to display the post's age like posted 2 hours ago. I figured if you put a timestamp every time the page reloads, and then compare/subtract it to the post's original timestamp, it would create a result similar to what I described. Is this however possible? If so, how can I do this?

Dranreb
  • 313
  • 3
  • 11
  • 1
    Do please first search google for PHP format timestamp and JavaScript convert date to days ago. Your questions are VERY FAQs. Also please ask one question at a time (but search first) – mplungjan May 07 '17 at 10:15
  • Okay sir my bad...I admit the question was pretty vague too. Thanks! :) – Dranreb May 07 '17 at 10:19

1 Answers1

2

In php you can format the variable coming from mysql.

$date = new DateTime("2017-05-07 16:12:44.415472");
$formatted = $date->format("N, F d, Y H:i");
abeyaz
  • 3,034
  • 1
  • 16
  • 20