Jump to content

Recommended Posts

Gotta excuse me.. I am fried, soo tired to much work at the 2 out of the box jobs.. but I wanna get this one thing done before I sleep before I go back to my job if possible.

 

I'm not using anything special.. just the normal time function to get a timestamp (maybe I should use something else, you tell me)..

 

But what I want to do is take:

 

Time1: 1208098153

and

Time2: 1208098351

 

^ for examples sake.. and make Time 3.. now time 3 is the amount of time that has passed between time 1 and 2.... But the kicker is that the duration between 1 and 2 could be a day, a few days, even a couple of months, who knows even longer. What I am ultimately doing is using the time stamps to convert them to actual readable date formats, but for the sake of coding using time stamps, as the dates are going to be displayed differently in different sections of the site. I don't know, I don't ask. I just do as I am told..

But this one thing is getting to me as tired as I am. I just want to break it down into seconds minutes hours days weeks months years.... and break it down to where if its only a few seconds or minute then show just the seconds or minutes or both pending example: 22min 38 seconds.. wanting a similar effect if it goes into hours days weeks months... I know I can break it down into over all seconds I think by subtracting the time 1 and 2.. but after a 24 hour period or so, I get negative numbers.. anyone able to help me out here? throw me a bone or just give me something to work with to make this guy happy I need sleep lol, ideas suggestions links to tutorials all welcome dont get me wrong I love to learn it to absorb the knowledge.. but im in a pinch so if you wanna just throw a working bit out by all means :-)

 

forget about months and years - the number of days in each isn't constant.

 

remember that there are 60 seconds in a minutes, 60 minutes in an hour, 24 hours in a day (and if you care, 7 days in a week).

 

Lay out some simple math involving the the difference in seconds with the floor() function and post your code attempts. We'll help from there.

forget about months and years - the number of days in each isn't constant.

 

remember that there are 60 seconds in a minutes, 60 minutes in an hour, 24 hours in a day (and if you care, 7 days in a week).

 

Lay out some simple math involving the the difference in seconds with the floor() function and post your code attempts. We'll help from there.

 

365 days in a yaer, 52 weeks in a year, 3600000 milliseconds in one hour

365 days in a yaer, 52 weeks in a year, 3600000 milliseconds in one hour

 

Was that helpful at all?  :-\

 

I didn't think so. 25% of years have more than 365 days, and every year has 52 weeks and a bit.  Any calculation that arbitrarily assume 365 days and 52 weeks is going to get the wrong answer.

ahh some responces, a couple hours of sleep.. an something to have critiqued.. this is what i've got.. thus far..

 

$org_tme = $result2a['start_time'];
$now_tme = time();

$diffr1 = $now_tme-$org_tme;

$days = floor($diffr1/86400);
$diffr2 = $diffr - ($days*86400);
$hours = floor($diffr2/3600); 
$diffr3 = $diffr - ($hours*3600); 
$min = floor($diffr/60); 
$sec = $diffr - ($diffr*60); 

 

then the display code is echoed out through if-else statements meaning if days are more then 7 it starts showing weeks, if days are more then 30 it starts showing months and then years go with the same effect. Generally speaking I know there is more then 30 days in some months and less in another, and with that also years have more then 52 weeks, and more then 365 days occasionally. But I am going to take the simple route and base it on a business billing style concept. 30 days is a month, 365 days is a year, and thats that, unless someone can help me come up with a concept for actually breaking it down accordingly, which as nice as that would be, isn't 100% necessary, at least not in this scenario, anyway.. the above code seems to work well.. any idea's how to improve, if there is anyway?

25% of years have more than 365 days, and every year has 52 weeks and a bit.  Any calculation that arbitrarily assume 365 days and 52 weeks is going to get the wrong answer.

 

i'll also add that any calculation that arbitrarily assumes 86400 seconds in a day is going to get the wrong answer. i suggest you switch out all of your time math to use mktime() for accurate time calculations.

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.