Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. convert time and minutes

convert time and minutes

Scheduled Pinned Locked Moved C#
help
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    onetreeup
    wrote on last edited by
    #1

    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

    P E 2 Replies Last reply
    0
    • O 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

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      New to C#? There appear to be a number of problems in your code; which statement is causing the error you mention?

      O 1 Reply Last reply
      0
      • P PIEBALDconsult

        New to C#? There appear to be a number of problems in your code; which statement is causing the error you mention?

        O Offline
        O Offline
        onetreeup
        wrote on last edited by
        #3

        Yes, I am new to C#, the error is being created from the Main method: string[] timeArray = new string[14]{"8:17", "15:26", "18:32", "0:46", "10:38", "13:56"};

        1 Reply Last reply
        0
        • O 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

          E Offline
          E Offline
          Edwin Brunner
          wrote on last edited by
          #4

          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!

          O 1 Reply Last reply
          0
          • E Edwin Brunner

            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!

            O Offline
            O Offline
            onetreeup
            wrote on last edited by
            #5

            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;

            E 1 Reply Last reply
            0
            • O onetreeup

              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;

              E Offline
              E Offline
              Edwin Brunner
              wrote on last edited by
              #6

              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; }

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups