convert time and minutes
-
I am working on a method to convert time, 00:00 to a double 00.00, and separate the minutes from the time to calculate elapsed time. I have two methods, but am getting a 'Invalid rank specifier: expected',' or ']' error. Hope this is not too long, please help. class TimeConversion { static void Main(string[] args) { string time = "00:00"; double hours = TimeSpan.Parse(time).TotalHours; double minutes = TimeSpan.Parse(time).TotalMinutes; string[] timeArray = new string[14]{"8:17", "15:26", "18:32", "0:46", "10:38", "13:56"}; //return timeArray; Convert.ToDecimal(timeArray); Console.WriteLine("8:17", "15:26", "18:32", "0:46", "10:38", "13:56"); Console.ReadKey(); } static double ConvertTime(string clockIn, string clockOut) { string time = "00:00"; double hours = TimeSpan.Parse(time).TotalHours; double minutes = TimeSpan.Parse(time).TotalMinutes; double dminutes = Convert.ToDouble(minutes); foreach ( if (dminutes >= .07) dminutes = 0.00; if (dminutes <= .22) dminutes = 0.25; if (dminutes <= .37) dminutes = 0.50; if (dminutes <= .53) dminutes = 0.75; if (dminutes > 53) dminutes = 1.0; return ConvertTime; } } Thanks OneTreeUp
-
I am working on a method to convert time, 00:00 to a double 00.00, and separate the minutes from the time to calculate elapsed time. I have two methods, but am getting a 'Invalid rank specifier: expected',' or ']' error. Hope this is not too long, please help. class TimeConversion { static void Main(string[] args) { string time = "00:00"; double hours = TimeSpan.Parse(time).TotalHours; double minutes = TimeSpan.Parse(time).TotalMinutes; string[] timeArray = new string[14]{"8:17", "15:26", "18:32", "0:46", "10:38", "13:56"}; //return timeArray; Convert.ToDecimal(timeArray); Console.WriteLine("8:17", "15:26", "18:32", "0:46", "10:38", "13:56"); Console.ReadKey(); } static double ConvertTime(string clockIn, string clockOut) { string time = "00:00"; double hours = TimeSpan.Parse(time).TotalHours; double minutes = TimeSpan.Parse(time).TotalMinutes; double dminutes = Convert.ToDouble(minutes); foreach ( if (dminutes >= .07) dminutes = 0.00; if (dminutes <= .22) dminutes = 0.25; if (dminutes <= .37) dminutes = 0.50; if (dminutes <= .53) dminutes = 0.75; if (dminutes > 53) dminutes = 1.0; return ConvertTime; } } Thanks OneTreeUp
New to C#? There appear to be a number of problems in your code; which statement is causing the error you mention?
-
New to C#? There appear to be a number of problems in your code; which statement is causing the error you mention?
-
I am working on a method to convert time, 00:00 to a double 00.00, and separate the minutes from the time to calculate elapsed time. I have two methods, but am getting a 'Invalid rank specifier: expected',' or ']' error. Hope this is not too long, please help. class TimeConversion { static void Main(string[] args) { string time = "00:00"; double hours = TimeSpan.Parse(time).TotalHours; double minutes = TimeSpan.Parse(time).TotalMinutes; string[] timeArray = new string[14]{"8:17", "15:26", "18:32", "0:46", "10:38", "13:56"}; //return timeArray; Convert.ToDecimal(timeArray); Console.WriteLine("8:17", "15:26", "18:32", "0:46", "10:38", "13:56"); Console.ReadKey(); } static double ConvertTime(string clockIn, string clockOut) { string time = "00:00"; double hours = TimeSpan.Parse(time).TotalHours; double minutes = TimeSpan.Parse(time).TotalMinutes; double dminutes = Convert.ToDouble(minutes); foreach ( if (dminutes >= .07) dminutes = 0.00; if (dminutes <= .22) dminutes = 0.25; if (dminutes <= .37) dminutes = 0.50; if (dminutes <= .53) dminutes = 0.75; if (dminutes > 53) dminutes = 1.0; return ConvertTime; } } Thanks OneTreeUp
I don't understand exactly what your problem is? Do you want to convert hours and minutes to decimal hours, ie. 12:45 would be 12.75? I have a couple of lines, which should work: static void Main(string[] args) { string[] timeArray = new string[] { "8:17", "15:26", "18:32", "0:46", "10:38", "13:56" }; foreach (string str in timeArray) { TimeSpan span = TimeSpan.Parse(str); Console.WriteLine(span.TotalHours.ToString("00.00")); } Console.ReadKey(); } Good luck!
-
I don't understand exactly what your problem is? Do you want to convert hours and minutes to decimal hours, ie. 12:45 would be 12.75? I have a couple of lines, which should work: static void Main(string[] args) { string[] timeArray = new string[] { "8:17", "15:26", "18:32", "0:46", "10:38", "13:56" }; foreach (string str in timeArray) { TimeSpan span = TimeSpan.Parse(str); Console.WriteLine(span.TotalHours.ToString("00.00")); } Console.ReadKey(); } Good luck!
Thanks, that work, my problem was placing a value in the [], but the second method that I am trying to resolve is separating the minutes in order to calculate the time based on the criteria. Time is based on minutes, for more than 7 minutes, no extra time, for more than 22 minutes, change to 0.25 (or 15 minutes). How can I add that to a for statement? if (dminutes >= .07) dminutes = 0.00; if (dminutes <= .22) dminutes = 0.25; if (dminutes <= .37) dminutes = 0.50; if (dminutes <= .53) dminutes = 0.75; if (dminutes > 53) dminutes = 1.0; return ConvertTime;
-
Thanks, that work, my problem was placing a value in the [], but the second method that I am trying to resolve is separating the minutes in order to calculate the time based on the criteria. Time is based on minutes, for more than 7 minutes, no extra time, for more than 22 minutes, change to 0.25 (or 15 minutes). How can I add that to a for statement? if (dminutes >= .07) dminutes = 0.00; if (dminutes <= .22) dminutes = 0.25; if (dminutes <= .37) dminutes = 0.50; if (dminutes <= .53) dminutes = 0.75; if (dminutes > 53) dminutes = 1.0; return ConvertTime;
like that? static void Main(string[] args) { string[] timeArray = new string[] { "8:17", "15:26", "18:32", "0:46", "10:38", "13:56" }; foreach (string str in timeArray) { TimeSpan span = TimeSpan.Parse(str); double dHours = span.TotalHours; Console.Write(dHours.ToString("00.00") + " "); dHours += GetExtraTime(span.Minutes); Console.WriteLine(dHours.ToString("00.00")); } Console.ReadKey(); } private static double GetExtraTime(int iMinutes) { if (iMinutes > 53) return 1.0; if (iMinutes > 37) return 0.75; if (iMinutes > 22) return 0.5; if (iMinutes > 7) return 0.25; return 0; }