Search results
Top results related to days and hours into seconds excel spreadsheet
Given an integer n(in seconds).Convert it into days, hours, minutes and seconds. Examples:
Input : 369121517 Output : 4272 days 5 hours 45 minutes 17 seconds Input : 129600 Output : 1 days 12 hours 0 minutes 0 seconds
Number of days = ? n / (24 * 3600) ? Number of Hours = ? (n % (24 * 3600)) / 3600 ? Number of Minutes = ? (n % (24 * 3600 * 3600)) / 60 ? Number of Seconds = ? (n % (24 * 3600 * 3600 * 60)) / 60 ?
C++
// C++ program to convert seconds // into days, hours,minutes,seconds #include <bits/stdc++.h> using namespace std; // function convert second into day // hours, minutes and seconds void ConvertSectoDay(int n) { int day = n / (24 * 3600); n = n % (24 * 3600); int hour = n / 3600; n %= 3600; int minutes = n / 60 ; n %= 60; int seconds = n; cout << day << " " << "days " << hour << " " << "hours " << minutes << " " << "minutes " << seconds << " " lt lt seconds lt lt...
1/5
Top Answer
Answered Nov 26, 2020 · 256 votes
This can be achieved with DateTime
class
Function:
function secondsToTime($seconds) { $dtF = new \DateTime('@0'); $dtT = new \DateTime("@$seconds"); return $dtF->diff($dtT)->format('%a days, %h hours, %i minutes and %s seconds');}
Use:
echo secondsToTime(1640467);# 18 days, 23 hours, 41 minutes and 7 seconds-
demo
Other Answers
Answered Aug 10, 2012 · 48 votes
This is the function rewritten to include days. I also changed the variable names to make the code easier to understand...
/** * Convert number of seconds into hours, minutes and seconds * and return an array containing those values * * @param integer $inputSeconds Number of seconds to parse * @return array */ function secondsToTime($inputSeconds) { $secondsInAMinute = 60; $secondsInAnHour = 60 * $secondsInAMinute; $secondsInADay = 24 * $secondsInAnHour; // extract days $days = floor($inputSeconds / $secondsInADay); // extract hours $hourSeconds = $inputSeconds % $secondsInADay; $hours = floor($hourSeconds / $secondsInAnHour); // extract minutes $minuteSeconds = $hourSeconds % $secondsInAnHour; $minutes = floor($minuteSeconds / $secondsInAMinute); // extract the remaining seconds $remainingSeconds = $minuteSeconds % $secondsInAMinute; $seconds = ceil($remainingSeconds); // return the final array $obj = array( 'd' => (int) $days, 'h' => (int) $hours, 'm' => (int) $minutes, 's' => (int) $seconds, ); return $obj;}
Source: CodeAid() - http://codeaid.net/php/convert-seconds-to-hours-minutes-and-seconds-(php)
Other Answers
Answered Jun 27, 2017 · 43 votes
Based on the answer by Julian Moreno, but changed to give the response as a string (not an array), only include the time intervals required and not assume the plural.
The difference between this and the highest voted answer is:
For 259264 seconds, this code would give
3 days, 1 minute, 4 seconds
For 259264 seconds, the highest voted answer (by Glavić) would give
3 days, 0 hours, 1 minutes and 4 seconds
function secondsToTime($inputSeconds) { $secondsInAMinute = 60; $secondsInAnHour = 60 * $secondsInAMinute; $secondsInADay = 24 * $secondsInAnHour; // Extract days $days = floor($inputSeconds / $secondsInADay); // Extract hours $hourSeconds = $inputSeconds % $secondsInADay; $hours = floor($hourSeconds / $secondsInAnHour); // Extract minutes $minuteSeconds = $hourSeconds % $secondsInAnHour; $minutes = floor($minuteSeconds / $secondsInAMinute); // Extract the remaining seconds $remainingSeconds = $minuteSeconds % $secondsInAMinute; $seconds = ceil($remainingSeconds); // Format and return $timeParts = []; $sections = [ 'day' => (int)$days, 'hour' => (int)$hours, 'minute' => (int)$minutes, 'second' => (int)$seconds, ]; foreach ($sections as $name => $value){ if ($value > 0){ $timeParts[] = $value. ' '.$name.($value == 1 ? '' : 's'); } } return implode(', ', $timeParts);}
I hope this helps someone.
2/5
Top Answer
Answered Sep 11, 2019 · 0 votes
Converting every variable to integer should erase decimals as you want, so use it like d = int(x/86400) for all of your variables (d, h, m and s).
3/5
Top Answer
Answered Aug 01, 2021 · 85 votes
This tidbit is useful for displaying elapsed time to varying degrees of granularity.
I personally think that questions of efficiency are practically meaningless here, so long as something grossly inefficient isn't being done. Premature optimization is the root of quite a bit of evil. This is fast enough that it'll never be your choke point.
intervals = ( ('weeks', 604800), # 60 * 60 * 24 * 7 ('days', 86400), # 60 * 60 * 24 ('hours', 3600), # 60 * 60 ('minutes', 60), ('seconds', 1),)def display_time(seconds, granularity=2): result = [] for name, count in intervals: value = seconds // count if value: seconds -= value * count if value == 1: name = name.rstrip('s') result.append("{} {}".format(value, name)) return ', '.join(result[:granularity])
..and this provides decent output:
In [52]: display_time(1934815)Out[52]: '3 weeks, 1 day'In [53]: display_time(1934815, 4)Out[53]: '3 weeks, 1 day, 9 hours, 26 minutes'
Other Answers
Answered Aug 10, 2012 · 48 votes
This is the function rewritten to include days. I also changed the variable names to make the code easier to understand...
/** * Convert number of seconds into hours, minutes and seconds * and return an array containing those values * * @param integer $inputSeconds Number of seconds to parse * @return array */ function secondsToTime($inputSeconds) { $secondsInAMinute = 60; $secondsInAnHour = 60 * $secondsInAMinute; $secondsInADay = 24 * $secondsInAnHour; // extract days $days = floor($inputSeconds / $secondsInADay); // extract hours $hourSeconds = $inputSeconds % $secondsInADay; $hours = floor($hourSeconds / $secondsInAnHour); // extract minutes $minuteSeconds = $hourSeconds % $secondsInAnHour; $minutes = floor($minuteSeconds / $secondsInAMinute); // extract the remaining seconds $remainingSeconds = $minuteSeconds % $secondsInAMinute; $seconds = ceil($remainingSeconds); // return the final array $obj = array( 'd' => (int) $days, 'h' => (int) $hours, 'm' => (int) $minutes, 's' => (int) $seconds, ); return $obj;}
Source: CodeAid() - http://codeaid.net/php/convert-seconds-to-hours-minutes-and-seconds-(php)
Other Answers
Answered Jun 27, 2017 · 43 votes
Based on the answer by Julian Moreno, but changed to give the response as a string (not an array), only include the time intervals required and not assume the plural.
The difference between this and the highest voted answer is:
For 259264 seconds, this code would give
3 days, 1 minute, 4 seconds
For 259264 seconds, the highest voted answer (by Glavić) would give
3 days, 0 hours, 1 minutes and 4 seconds
function secondsToTime($inputSeconds) { $secondsInAMinute = 60; $secondsInAnHour = 60 * $secondsInAMinute; $secondsInADay = 24 * $secondsInAnHour; // Extract days $days = floor($inputSeconds / $secondsInADay); // Extract hours $hourSeconds = $inputSeconds % $secondsInADay; $hours = floor($hourSeconds / $secondsInAnHour); // Extract minutes $minuteSeconds = $hourSeconds % $secondsInAnHour; $minutes = floor($minuteSeconds / $secondsInAMinute); // Extract the remaining seconds $remainingSeconds = $minuteSeconds % $secondsInAMinute; $seconds = ceil($remainingSeconds); // Format and return $timeParts = []; $sections = [ 'day' => (int)$days, 'hour' => (int)$hours, 'minute' => (int)$minutes, 'second' => (int)$seconds, ]; foreach ($sections as $name => $value){ if ($value > 0){ $timeParts[] = $value. ' '.$name.($value == 1 ? '' : 's'); } } return implode(', ', $timeParts);}
I hope this helps someone.
4/5
Top Answer
Answered Aug 01, 2021 · 85 votes
This tidbit is useful for displaying elapsed time to varying degrees of granularity.
I personally think that questions of efficiency are practically meaningless here, so long as something grossly inefficient isn't being done. Premature optimization is the root of quite a bit of evil. This is fast enough that it'll never be your choke point.
intervals = ( ('weeks', 604800), # 60 * 60 * 24 * 7 ('days', 86400), # 60 * 60 * 24 ('hours', 3600), # 60 * 60 ('minutes', 60), ('seconds', 1),)def display_time(seconds, granularity=2): result = [] for name, count in intervals: value = seconds // count if value: seconds -= value * count if value == 1: name = name.rstrip('s') result.append("{} {}".format(value, name)) return ', '.join(result[:granularity])
..and this provides decent output:
In [52]: display_time(1934815)Out[52]: '3 weeks, 1 day'In [53]: display_time(1934815, 4)Out[53]: '3 weeks, 1 day, 9 hours, 26 minutes'
Other Answers
Answered Aug 10, 2012 · 48 votes
This is the function rewritten to include days. I also changed the variable names to make the code easier to understand...
/** * Convert number of seconds into hours, minutes and seconds * and return an array containing those values * * @param integer $inputSeconds Number of seconds to parse * @return array */ function secondsToTime($inputSeconds) { $secondsInAMinute = 60; $secondsInAnHour = 60 * $secondsInAMinute; $secondsInADay = 24 * $secondsInAnHour; // extract days $days = floor($inputSeconds / $secondsInADay); // extract hours $hourSeconds = $inputSeconds % $secondsInADay; $hours = floor($hourSeconds / $secondsInAnHour); // extract minutes $minuteSeconds = $hourSeconds % $secondsInAnHour; $minutes = floor($minuteSeconds / $secondsInAMinute); // extract the remaining seconds $remainingSeconds = $minuteSeconds % $secondsInAMinute; $seconds = ceil($remainingSeconds); // return the final array $obj = array( 'd' => (int) $days, 'h' => (int) $hours, 'm' => (int) $minutes, 's' => (int) $seconds, ); return $obj;}
Source: CodeAid() - http://codeaid.net/php/convert-seconds-to-hours-minutes-and-seconds-(php)
Other Answers
Answered Jun 27, 2017 · 43 votes
Based on the answer by Julian Moreno, but changed to give the response as a string (not an array), only include the time intervals required and not assume the plural.
The difference between this and the highest voted answer is:
For 259264 seconds, this code would give
3 days, 1 minute, 4 seconds
For 259264 seconds, the highest voted answer (by Glavić) would give
3 days, 0 hours, 1 minutes and 4 seconds
function secondsToTime($inputSeconds) { $secondsInAMinute = 60; $secondsInAnHour = 60 * $secondsInAMinute; $secondsInADay = 24 * $secondsInAnHour; // Extract days $days = floor($inputSeconds / $secondsInADay); // Extract hours $hourSeconds = $inputSeconds % $secondsInADay; $hours = floor($hourSeconds / $secondsInAnHour); // Extract minutes $minuteSeconds = $hourSeconds % $secondsInAnHour; $minutes = floor($minuteSeconds / $secondsInAMinute); // Extract the remaining seconds $remainingSeconds = $minuteSeconds % $secondsInAMinute; $seconds = ceil($remainingSeconds); // Format and return $timeParts = []; $sections = [ 'day' => (int)$days, 'hour' => (int)$hours, 'minute' => (int)$minutes, 'second' => (int)$seconds, ]; foreach ($sections as $name => $value){ if ($value > 0){ $timeParts[] = $value. ' '.$name.($value == 1 ? '' : 's'); } } return implode(', ', $timeParts);}
I hope this helps someone.
5/5
People also ask
How to convert seconds into days hours and minutes in Excel?
- This tutorial will demonstrate how to convert seconds into days, hours and minutes in Excel and Google Spreadsheets. First, divide the number of seconds by 86400 (the number of seconds in a day). After doing this you will get the hour value as a number.
Convert seconds to minutes / hours / time - Excel and Google
www.automateexcel.com/formulas/convert-seconds-to-minutes-hours/How to convert time to seconds in Excel?
- One more way to get the number of minutes is to multiply hours by 60 and divide seconds by the same number: Converting time to total seconds in Excel can be done in a similar fashion. Multiply the time value by 86400, which is the number of seconds in a day (24 hours * 60 minutes * 60 seconds = 86400):
Excel: convert time to decimal number, hours, minutes or seconds - Abl…
www.ablebits.com/office-addins-blog/excel-convert-time-decimal/How do I convert seconds to hours in Google Spreadsheets?
- In Google Spreadsheets, you use the same formula you use in Excel to convert seconds to hours by dividing the value by 86400. You then use custom formatting to display the hours, as well as the minutes and seconds. In Google Spreadsheets, you use the same formula you use in Excel to convert seconds into hours, by dividing the value by 86400.
Convert seconds to minutes / hours / time - Excel and Google
www.automateexcel.com/formulas/convert-seconds-to-minutes-hours/How do you convert time to decimal in Excel?
- The easiest way to convert time to decimal in Excel is to multiply the original time value by the number of hours, seconds or minutes in a day: To convert time to a number of hours, multiply the time by 24, which is the number of hours in a day. To convert time to minutes, multiply the time by 1440, which is the number of minutes in a day (24*60).
Excel: convert time to decimal number, hours, minutes or seconds - Abl…
www.ablebits.com/office-addins-blog/excel-convert-time-decimal/www.automateexcel.com › formulas › convert-secondsConvert seconds to minutes / hours / time - Automate Excel
www.automateexcel.com › formulas › convert-secondsJul 5, 2023 · This tutorial will demonstrate how to convert seconds into days, hours and minutes in Excel and Google Spreadsheets. Converting seconds to minutes and seconds First, divide the number of seconds by 86400 (the number of seconds in a day).
stackoverflow.com › questions › 66772170How to convert dd:hh:mm:ss format time into seconds in Excel ...
stackoverflow.com › questions › 66772170Mar 23, 2021 · 1. =IF(LEN(A2)-LEN(SUBSTITUTE(A2;":";""))=3;DAY(LEFT(A2;SEARCH(":";A2)-1))*24*3600+HOUR(RIGHT(A2;LEN(A2)-SEARCH(":";A2)))*3600+MINUTE(RIGHT(A2;LEN(A2)-SEARCH(":";A2)))*60+SECOND(RIGHT(A2;LEN(A2)-SEARCH(":";A2)));HOUR(A2)*3600+MINUTE(A2)*60+SECOND(A2))
Usage example
=IFERROR(A14*86400,(LEFT(A14,FIND(":",A14)-1)+ MID(A14,FIND(":",A14)+1,99))*86400)www.ablebits.com › office-addins-blog › excelExcel: convert time to decimal number, hours, minutes or seconds
www.ablebits.com › office-addins-blog › excelMar 21, 2023 · The easiest way to convert time to decimal in Excel is to multiply the original time value by the number of hours, seconds or minutes in a day: To convert time to a number of hours, multiply the time by 24, which is the number of hours in a day. To convert time to minutes, multiply the time by 1440, which is the number of minutes in a day (24*60).
- Svetlana Cheusheva
www.howtoexcel.org › format-time-values9 Ways to Format Time in Microsoft Excel | How To Excel
www.howtoexcel.org › format-time-valuesMay 10, 2024 · To convert the entries in the time column ( Call Time) to time data as hours: minutes: and seconds, highlight the column or the cell range.
www.exceldemy.com › convert-seconds-to-hoursHow to Convert Seconds to Hours Minutes Seconds in Excel
www.exceldemy.com › convert-seconds-to-hoursDec 21, 2023 · This article shows how to convert seconds to hours minutes seconds Excel using CONVERT, MATCH, and CHOOSE functions and Format Cells Option.
answers.microsoft.com › en-us › msofficeHow can I convert 141899 seconds into Days, hours, Mins, secs
answers.microsoft.com › en-us › msofficeJul 14, 2022 · You can try using the MS Excel to try the conversion. You then use custom formatting to display the days as well as the hours, minutes and seconds. 1. Delete the formatting in the Custom date and time formats box, and then click on the drop-down box to the right of the custom format box to display all the date and time options. 2.
spreadsheetplanet.com › convert-time-to-decimal-excelConvert Time to Decimal in Excel - Spreadsheet Planet
spreadsheetplanet.com › convert-time-to-decimal-excel1. In cell B2, type the following formula and hit the Enter button. =A2*24. You will see the decimal representation of the time value 12:05:30 as below. 2. Copy the formula and paste it across the remaining rows in the column to get the decimal time values for respective cells.
Searches related to days and hours into seconds excel spreadsheet