seconds to time

Get help on web editors (Frontpage, Dreamweaver) and web languages (HTML, ASP, PHP).
Post Reply
DarkRanger
Registered User
Posts: 8346
Joined: 10 May 2006, 02:00
Processor: Intel i5-3750
Motherboard: Gigabyte
Graphics card: nVidia GTX 550Ti
Memory: 8GB Jetram
Contact:

seconds to time

Post 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?
Image
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Re: seconds to time

Post by rustypup »

is this a timestamp or a counter?
Most people would sooner die than think; in fact, they do so - Bertrand Russel
User avatar
Ron2K
Forum Technical Administrator
Posts: 9050
Joined: 04 Jul 2006, 16:45
Location: Upper Hutt, New Zealand
Contact:

Re: seconds to time

Post by Ron2K »

Which language? C# has the TimeSpan struct if that's your poison.
Kia kaha, Kia māia, Kia manawanui.
Bladerunner
Registered User
Posts: 14338
Joined: 04 Sep 2004, 02:00
Processor: i386DX Sooper
Motherboard: A blue one
Graphics card: A red one
Memory: Hard drive
Location: On a Möbius strip
Contact:

Re: seconds to time

Post 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.
If I weren't insane: I couldn't be so brilliant! - The Joker
User avatar
KatrynKat
Insane in the Membrane
Posts: 24490
Joined: 18 Jul 2010, 17:42
Location: In my BDSM dungeon - aka Lockdown

Re: seconds to time

Post 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...
"This eBook is displayed using 100% recycled electrons."
Bladerunner
Registered User
Posts: 14338
Joined: 04 Sep 2004, 02:00
Processor: i386DX Sooper
Motherboard: A blue one
Graphics card: A red one
Memory: Hard drive
Location: On a Möbius strip
Contact:

Re: seconds to time

Post 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.
If I weren't insane: I couldn't be so brilliant! - The Joker
RuadRauFlessa
Registered User
Posts: 20576
Joined: 19 Sep 2003, 02:00
Location: Bloodbank

Re: seconds to time

Post by RuadRauFlessa »

the question remains what language?
:rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock:
Spoiler (show)
Intel Core i7-2600k @ 3.4GHz
Corsair Vengence 2x4GB DDR3 2000MHz
Thermaltake Toughpower 850W
ASUS nVidia GTX560 1GB
CoolerMaster HAF 932
User avatar
rustypup
Registered User
Posts: 8872
Joined: 13 Dec 2004, 02:00
Location: nullus pixius demonica
Contact:

Re: seconds to time

Post 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...
Most people would sooner die than think; in fact, they do so - Bertrand Russel
Bladerunner
Registered User
Posts: 14338
Joined: 04 Sep 2004, 02:00
Processor: i386DX Sooper
Motherboard: A blue one
Graphics card: A red one
Memory: Hard drive
Location: On a Möbius strip
Contact:

Re: seconds to time

Post 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
If I weren't insane: I couldn't be so brilliant! - The Joker
DarkRanger
Registered User
Posts: 8346
Joined: 10 May 2006, 02:00
Processor: Intel i5-3750
Motherboard: Gigabyte
Graphics card: nVidia GTX 550Ti
Memory: 8GB Jetram
Contact:

Re: seconds to time

Post 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.
Image
Bladerunner
Registered User
Posts: 14338
Joined: 04 Sep 2004, 02:00
Processor: i386DX Sooper
Motherboard: A blue one
Graphics card: A red one
Memory: Hard drive
Location: On a Möbius strip
Contact:

Re: seconds to time

Post 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?
If I weren't insane: I couldn't be so brilliant! - The Joker
RuadRauFlessa
Registered User
Posts: 20576
Joined: 19 Sep 2003, 02:00
Location: Bloodbank

Re: seconds to time

Post by RuadRauFlessa »

OK.... So allow me to google that for you....
:rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock:
Spoiler (show)
Intel Core i7-2600k @ 3.4GHz
Corsair Vengence 2x4GB DDR3 2000MHz
Thermaltake Toughpower 850W
ASUS nVidia GTX560 1GB
CoolerMaster HAF 932
DarkRanger
Registered User
Posts: 8346
Joined: 10 May 2006, 02:00
Processor: Intel i5-3750
Motherboard: Gigabyte
Graphics card: nVidia GTX 550Ti
Memory: 8GB Jetram
Contact:

Re: seconds to time

Post 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...
Image
DarkRanger
Registered User
Posts: 8346
Joined: 10 May 2006, 02:00
Processor: Intel i5-3750
Motherboard: Gigabyte
Graphics card: nVidia GTX 550Ti
Memory: 8GB Jetram
Contact:

Re: seconds to time

Post 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:
Last edited by DarkRanger on 14 Sep 2011, 09:19, edited 1 time in total.
Image
doo_much
Registered User
Posts: 26022
Joined: 13 May 2004, 02:00
Location: Getting there...
Contact:

Re: seconds to time

Post by doo_much »

MOOD - Thirsty

A surprising amount of modern pseudoscience is coming out of the environmental sector. Perhaps it should not be so surprising given that environmentalism is political rather than scientific.
Timothy Casey
RuadRauFlessa
Registered User
Posts: 20576
Joined: 19 Sep 2003, 02:00
Location: Bloodbank

Re: seconds to time

Post 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...
:rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock:
Spoiler (show)
Intel Core i7-2600k @ 3.4GHz
Corsair Vengence 2x4GB DDR3 2000MHz
Thermaltake Toughpower 850W
ASUS nVidia GTX560 1GB
CoolerMaster HAF 932
DarkRanger
Registered User
Posts: 8346
Joined: 10 May 2006, 02:00
Processor: Intel i5-3750
Motherboard: Gigabyte
Graphics card: nVidia GTX 550Ti
Memory: 8GB Jetram
Contact:

Re: seconds to time

Post by DarkRanger »

doo_much wrote:I doo_much of Google too...

PHP function to convert seconds to human readable string
fixxed :lol: :lol:
Image
doo_much
Registered User
Posts: 26022
Joined: 13 May 2004, 02:00
Location: Getting there...
Contact:

Re: seconds to time

Post 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:
MOOD - Thirsty

A surprising amount of modern pseudoscience is coming out of the environmental sector. Perhaps it should not be so surprising given that environmentalism is political rather than scientific.
Timothy Casey
DarkRanger
Registered User
Posts: 8346
Joined: 10 May 2006, 02:00
Processor: Intel i5-3750
Motherboard: Gigabyte
Graphics card: nVidia GTX 550Ti
Memory: 8GB Jetram
Contact:

Re: seconds to time

Post by DarkRanger »

Awesome. Found a function that works the bomb! Thanks guys!
Image
Bladerunner
Registered User
Posts: 14338
Joined: 04 Sep 2004, 02:00
Processor: i386DX Sooper
Motherboard: A blue one
Graphics card: A red one
Memory: Hard drive
Location: On a Möbius strip
Contact:

Re: seconds to time

Post 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:
If I weren't insane: I couldn't be so brilliant! - The Joker
DarkRanger
Registered User
Posts: 8346
Joined: 10 May 2006, 02:00
Processor: Intel i5-3750
Motherboard: Gigabyte
Graphics card: nVidia GTX 550Ti
Memory: 8GB Jetram
Contact:

Re: seconds to time

Post 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)
Image
RuadRauFlessa
Registered User
Posts: 20576
Joined: 19 Sep 2003, 02:00
Location: Bloodbank

Re: seconds to time

Post by RuadRauFlessa »

Glad to be of service :P
:rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock: :rock:
Spoiler (show)
Intel Core i7-2600k @ 3.4GHz
Corsair Vengence 2x4GB DDR3 2000MHz
Thermaltake Toughpower 850W
ASUS nVidia GTX560 1GB
CoolerMaster HAF 932
Post Reply