seconds to time
-
- 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
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?
For example: 12353251 seconds translates to: 1 year, 5 months, 1 week, 3 days, 10 hours, 38 minutes and 11 seconds?
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
Re: seconds to time
is this a timestamp or a counter?
Most people would sooner die than think; in fact, they do so - Bertrand Russel
- Ron2K
- Forum Technical Administrator
- Posts: 9050
- Joined: 04 Jul 2006, 16:45
- Location: Upper Hutt, New Zealand
- Contact:
Re: seconds to time
Which language? C# has the TimeSpan struct if that's your poison.
Kia kaha, Kia māia, Kia manawanui.
-
- 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
Doesn't sound right. A year is roughly 2.5 times as many seconds.DarkRanger wrote:12353251 seconds translates to: 1 year, 5 months, 1 week, 3 days, 10 hours, 38 minutes and 11 seconds?
If I weren't insane: I couldn't be so brilliant! - The Joker
- KatrynKat
- Insane in the Membrane
- Posts: 24490
- Joined: 18 Jul 2010, 17:42
- Location: In my BDSM dungeon - aka Lockdown
Re: seconds to time
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...
cause 1yr, 5m, 1w, 3d,10hr, 38min and 11sec = 45398291secs...
"This eBook is displayed using 100% recycled electrons."
-
- 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
Using this piece of SAS code (since I'm at work and don't have access to a proper language):
I get that your given seconds equate to:
0 years, 4 months, 3 weeks, 0 days, 5 hours, 27 mins, 1 sec.
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;
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
-
- Registered User
- Posts: 20576
- Joined: 19 Sep 2003, 02:00
- Location: Bloodbank
- rustypup
- Registered User
- Posts: 8872
- Joined: 13 Dec 2004, 02:00
- Location: nullus pixius demonica
- Contact:
Re: seconds to time
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...
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
-
- 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
Hence the "approx" comment in my code. I did what I could with what I hadrustypup wrote:you can't calculate months off of a counter because it has no frame of reference...
If I weren't insane: I couldn't be so brilliant! - The Joker
-
- 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
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.
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.
-
- 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
Should it even be open for anything more than a few days or even hours?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.
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
-
- Registered User
- Posts: 20576
- Joined: 19 Sep 2003, 02:00
- Location: Bloodbank
-
- 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
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!!
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...
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!!
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...
-
- 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
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
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!
Sarcasm by the way. Here is my search history from yesterday. Thank you for your concern
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!
Last edited by DarkRanger on 14 Sep 2011, 09:19, edited 1 time in total.
-
- Registered User
- Posts: 26022
- Joined: 13 May 2004, 02:00
- Location: Getting there...
- Contact:
Re: seconds to time
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
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
-
- Registered User
- Posts: 20576
- Joined: 19 Sep 2003, 02:00
- Location: Bloodbank
Re: seconds to time
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...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
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!
- Spoiler (show)
-
- 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
fixxed
-
- Registered User
- Posts: 26022
- Joined: 13 May 2004, 02:00
- Location: Getting there...
- Contact:
Re: seconds to time
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!
So the only solution I see open for you is to ensure that your colleagues close every job before 4 weeks are up!
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
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
-
- 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
Awesome. Found a function that works the bomb! Thanks guys!
-
- 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
What's wrong with "15 weeks" ?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!
If I weren't insane: I couldn't be so brilliant! - The Joker
-
- 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
Nah, weeks work perfect. Thanks!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!
-
- Registered User
- Posts: 20576
- Joined: 19 Sep 2003, 02:00
- Location: Bloodbank