Jump to content

[SOLVED] Subtract time?


Crew-Portal

Recommended Posts

Okay all my times are set to

$date = date('D M d, Y g:i a');

And this works fine posting data to MySQL but how do I get it so that it can take the time posted in the mysql which has the rowname `postdate` and subtract the time now so it can display something like:

 

"POSTED PIREP 1365 Minutes Ago"

 

You know? Any suggestions?

Link to comment
Share on other sites

Doesnt seem to work! If someone could make it simpler by lets say I wanna subtract 2 hours 5 mins and 18 seconds from the current time, if someone could write the code showing how to do that it would be a life saver, then I could figure out myself on how to imply it to mySQL I looked on PHP.net but I couldnt understand how to do it, each time I tried I got a result that I didnt want.

 

I know im asking for a bit but if someone could just lend me like 3 mins and write to code... -2 hours 5 mins and 18 seconds

Link to comment
Share on other sites

from what i've found, when doing date and time math it is easiest to convert the time to the unix time stamp. that way you are dealing with one unit(seconds) and not multiple units like days, minutes, seconds, etc. so if you need to tell the difference between 2 dates/times, you could convert them both to their unix equivalents and do the math from there. example:

 

$time1 = strtotime($time1);
$time2 = strtotime($time2);
$diff = $time2- $time1;
$output = date("h:i:s", $diff);

 

Now if you want to subtract from the current time all you have to do is:

 

strtotime("-2 hours 5 minutes 18 seconds");

 

I doubt that is what you really want to do since you have a time stored in a database though. I think you will find the first option to be what you want with a little work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.