Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert minutes to full time C#

Tags:

c#

datetime

time

I need convert 1815 minutes to 30:15 (30 hours and 15 minutes)

Is there an easy way to do this that I am missing?

like image 230
soamazing Avatar asked Jan 11 '12 12:01

soamazing


People also ask

How do you convert minutes to payroll?

All you need to do is divide your minutes by 60. For example, say your employee worked 20 hours and 15 minutes during the week. Divide your total minutes by 60 to get your decimal. For this pay period, your employee worked 20.25 hours.

What is the formula to convert minutes to hours?

There are 60 minutes in 1 hour. To convert from minutes to hours, divide the number of minutes by 60. For example, 120 minutes equals 2 hours because 120/60=2. Created by Sal Khan.

What does 0.25 mean in minutes?

For example 15 minutes (¼ hour) equals . 25, 30 minutes (½ hour) equals . 5, etc.


2 Answers

Use TimeSpan.FromMinutes:

var result = TimeSpan.FromMinutes(1815);

This will give you an object that you can use in different ways.
For example:

var hours = (int)result.TotalHours;
var minutes = result.Minutes;
like image 146
Daniel Hilgarth Avatar answered Oct 02 '22 16:10

Daniel Hilgarth


you can use this function


//minutes to be converted (70minutes = 1:10 hours)
int totalminutes = 70;
//total hours
int hours = 70 / 60;
//total minutes
int minutes = 70 % 60;
//output is 1:10
var time = string.Format("{0} : {1}", hours, minutes);
like image 38
Giorgio Minardi Avatar answered Oct 02 '22 15:10

Giorgio Minardi