0

I'm making a text based PHP game. Every second there is an update, and update, the row time gets selected from the database, containing for example 548991. That means 548991 minutes have gone by, so that means that for example its the first year, the first month, the 4th day, the 7th hour and the 51th minute. How can i calculate that, so that the number 548991 results into: Year 1, Month 1, Day 4, 07:51 AM using PHP code?

Thew
  • 15,789
  • 18
  • 59
  • 100
  • you are supposed to use the search function before asking. How to format a timestamp and a date to relative time has been answered multiple times before and I take you are smart enough to convert seconds to minutes on your own. – Gordon May 18 '12 at 11:50
  • @Gordon I did search, i'm not new to Stackoverflow and i know the rules, but mathematical questions are not my best side, i've been stuck on this for a few hours now. – Thew May 18 '12 at 11:52
  • possible duplicate of [Relative Date from Unix Timestamp with PHP](http://stackoverflow.com/questions/8244642/relative-date-from-unix-timestamp-with-php) – Gordon May 18 '12 at 11:54
  • possible duplicate of http://stackoverflow.com/search?q=relative+time+php – Gordon May 18 '12 at 11:55
  • @Gordon Still haven't found my solution between those. – Thew May 18 '12 at 12:05
  • possible duplicate of [PHP Time Since Function?](http://stackoverflow.com/questions/5010016/php-time-since-function) – jprofitt May 18 '12 at 12:13
  • The point is that you need to convert your value in minutes to seconds in order to have a unix timestamp, which will let you use all of the time family of functions (just multiply your minutes value by 60 and take a look in any of the references offered by the others). – Yaniro May 18 '12 at 12:30

1 Answers1

7

Alot of extra effort is spent not answering this question. Also, Thew, I know you didn't give up, so answering your own question when you find a solution would have been good for your Karma.

My grandfather once told me you catch more flies with honey. I get what these guys are saying, but I just think we should all treat each other a little better.

Answering with some tags...

Answering with some code...

$datetime1 = new DateTime('now - {$minutes}minutes');
$datetime2 = new DateTime('now');
$interval = date_diff($datetime2,$datetime1);
echo $interval->format('%r Year %y, Month %m, Day %d, %H:%I %a');

Answering removes this question from the unanswered list...

Peace

Shanimal
  • 11,517
  • 7
  • 63
  • 76
  • 4
    Ever thought of becoming a teacher? You are simply awesome. All the kids at school will love you. – Thew Jun 05 '12 at 15:00