Page 1 of 1

seconds to time

Posted: 13 Sep 2011, 11:45
by DarkRanger
I've got a variable with a certain amount of seconds stored in it. How do I get it to show months, weeks, days, hours, minutes, seconds?

For example: 12353251 seconds translates to: 1 year, 5 months, 1 week, 3 days, 10 hours, 38 minutes and 11 seconds?

Re: seconds to time

Posted: 13 Sep 2011, 12:54
by rustypup
is this a timestamp or a counter?

Re: seconds to time

Posted: 13 Sep 2011, 13:12
by Ron2K
Which language? C# has the TimeSpan struct if that's your poison.

Re: seconds to time

Posted: 13 Sep 2011, 13:35
by Bladerunner
DarkRanger wrote:12353251 seconds translates to: 1 year, 5 months, 1 week, 3 days, 10 hours, 38 minutes and 11 seconds?
Doesn't sound right. A year is roughly 2.5 times as many seconds.

Re: seconds to time

Posted: 13 Sep 2011, 13:49
by KatrynKat
i think he just used that as an example of how he wants the output to look...

cause 1yr, 5m, 1w, 3d,10hr, 38min and 11sec = 45398291secs...

Re: seconds to time

Posted: 13 Sep 2011, 13:51
by Bladerunner
Using this piece of SAS code (since I'm at work and don't have access to a proper language):

Code: Select all

data Interpret;
	secs =  12353251;

	/*Constants*/
	year_ = floor(3600 * 24 * 365.25);
	month_ = (3600 * 24 * 365.25) / 12; /* Approx */
	week_ = 3600 * 24 * 7;
	day_ = 3600 * 24;
	hour_ = 3600;
	min_ = 60;
	sec_ = 1;

	%macro GetVars(var=);
		if secs > &var._ then do;
			mod = mod(secs, &var._);
			&var.s = (secs - mod(secs, &var._)) / &var._;
			secs = mod;
		end;
		else &var.s = 0;
	%mend GetVars;
	%GetVars(var=year);
	%GetVars(var=month);
	%GetVars(var=week);
	%GetVars(var=day);
	%GetVars(var=hour);
	%GetVars(var=min);
	%GetVars(var=sec);
run;
I get that your given seconds equate to:
0 years, 4 months, 3 weeks, 0 days, 5 hours, 27 mins, 1 sec.

Re: seconds to time

Posted: 13 Sep 2011, 14:22
by RuadRauFlessa
the question remains what language?

Re: seconds to time

Posted: 13 Sep 2011, 14:29
by rustypup
you can't calculate months off of a counter because it has no frame of reference...

days/weeks/years are fine as are hours/minutes and seconds... months is meaningless unless you're arbitrarily assigning a fixed value of days/month... (365.25/12)....

we still don't know if it's a timestamp or not...

if it's a counter, a recursive modulus operation would produce the necessary detail...

Re: seconds to time

Posted: 13 Sep 2011, 14:54
by Bladerunner
rustypup wrote:you can't calculate months off of a counter because it has no frame of reference...
Hence the "approx" comment in my code. I did what I could with what I had :P

Re: seconds to time

Posted: 14 Sep 2011, 08:34
by DarkRanger
Sorry, language is PHP.

Also thought about the months thing. So was thinking perhaps weeks as a max...

This is a counter. Basically it reflects the time that a Support ticket's been open.

Re: seconds to time

Posted: 14 Sep 2011, 09:05
by Bladerunner
DarkRanger wrote:Sorry, language is PHP.

Also thought about the months thing. So was thinking perhaps weeks as a max...

This is a counter. Basically it reflects the time that a Support ticket's been open.
Should it even be open for anything more than a few days or even hours? :shock:

EDIT:
And furthermore, why not put the unix epoch in the database and work from that?

Re: seconds to time

Posted: 14 Sep 2011, 09:13
by RuadRauFlessa
OK.... So allow me to google that for you....

Re: seconds to time

Posted: 14 Sep 2011, 09:15
by DarkRanger
I missed one word in my explenation... 'average'.

It reflects the 'average' time that a support ticket's been open. And in our office sometimes it does stretch a few days. Let's just say IT is outnumbered 130:1. and that is a 1:1 statement!! :P

So to get average, I take the amount of time that any closed ticket has been open (strtotime($date) where date was read from the database) and add it all together. So now I get a total open time in seconds. And I divide it by the amount of closed tickets.

So let's say total time (in s) = 312589235
Total CLOSED tickets = 58
Average closed time = 312589235 / 58 = 5389469.568965517 (which I floor to 5389469)

Now I want to see 5389469 in weeks, days, hours etc...

Re: seconds to time

Posted: 14 Sep 2011, 09:17
by DarkRanger
WHY thank you for that. I was so lost... This new google tool... Where'd you find it?

^^ Sarcasm by the way. Here is my search history from yesterday. Thank you for your concern :P

http://www.google.co.za/search?q=change ... 00&bih=809
http://www.google.co.za/search?q=change ... =firefox-a
http://www.google.co.za/search?q=DATE+P ... =firefox-a


EDIT TO ADD: And yet you got other result that me! :lol:

Re: seconds to time

Posted: 14 Sep 2011, 09:19
by doo_much

Re: seconds to time

Posted: 14 Sep 2011, 09:22
by RuadRauFlessa
DarkRanger wrote:WHY thank you for that. I was so lost... This new google tool... Where'd you find it?

^^ Sarcasm by the way. Here is my search history from yesterday. Thank you for your concern :P

http://www.google.co.za/search?q=change ... 00&bih=809
http://www.google.co.za/search?q=change ... =firefox-a
http://www.google.co.za/search?q=DATE+P ... =firefox-a


EDIT TO ADD: And yet you got other result that me! :lol:
could be because you are using firefox and google is discrimitating against you or it could be that you searched for "DATE PHP"... just a thought...

Re: seconds to time

Posted: 14 Sep 2011, 09:23
by DarkRanger
doo_much wrote:I doo_much of Google too...

PHP function to convert seconds to human readable string
fixxed :lol: :lol:

Re: seconds to time

Posted: 14 Sep 2011, 09:26
by doo_much
Interesting one though - that only converts to weeks. If you need to start doing so for months - what are you going to use as basis? 30 day months or 31. And don't let's get started about February!

So the only solution I see open for you is to ensure that your colleagues close every job before 4 weeks are up! :lol:

Re: seconds to time

Posted: 14 Sep 2011, 09:29
by DarkRanger
Awesome. Found a function that works the bomb! Thanks guys!

Re: seconds to time

Posted: 14 Sep 2011, 09:29
by Bladerunner
doo_much wrote:Interesting one though - that only converts to weeks. If you need to start doing so for months - what are you going to use as basis? 30 day months or 31. And don't let's get started about February!

So the only solution I see open for you is to ensure that your colleagues close every job before 4 weeks are up! :lol:
What's wrong with "15 weeks" ? :wink:

Re: seconds to time

Posted: 14 Sep 2011, 09:29
by DarkRanger
doo_much wrote:Interesting one though - that only converts to weeks. If you need to start doing so for months - what are you going to use as basis? 30 day months or 31. And don't let's get started about February!

So the only solution I see open for you is to ensure that your colleagues close every job before 4 weeks are up! :lol:
Nah, weeks work perfect. Thanks! 8)

Re: seconds to time

Posted: 14 Sep 2011, 09:53
by RuadRauFlessa
Glad to be of service :P