Solved

# How to get days, hours, minutes, seconds from a large seconds value.

Posted on 2013-01-08
548 Views
\$num_of_seconds = 172870;

#how to get dd days, hh hours, mm minutes, and ss seconds?  So it will be like 2 days 0 hours 1 minutes 10 seconds.
0
Question by:rgbcof
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 31

Accepted Solution

farzanj earned 500 total points
ID: 38757552
``````my \$num_of_seconds = 172870;
my \$dd = int(\$num_of_seconds / 86400);
my \$hh = int(int((\$num_of_seconds % 86400)) / 3600);
my \$mm = int(int((\$num_of_seconds % 86400) % 3600) /60);
my \$ss = int(int((\$num_of_seconds % 86400) % 3600) %60);
``````
0

LVL 84

Expert Comment

ID: 38758077
#or
my \$num_of_seconds = 172870;
my(\$ss,\$mm,\$hh,\$dd)=(gmtime \$num_of_seconds)[0,1,2,7];   #but this only works up to 364 days
#the simplest way to extend it beyond 364 days may be to add another variable.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
###### Suggested Courses
Course of the Month7 days, 20 hours left to enroll