Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7418151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:49:58+00:00 2026-05-29T07:49:58+00:00

Hello people i am doing an app on C# and now i am with

  • 0

Hello people i am doing an app on C# and now i am with a doubt.

I need to represent relative time, for example i have 02:30:00 i will need to say that is 2,5 hours.

How can i do that, and i need that have to be with 2 decimals here is what i have done so far, but i gives me errors with timespan

private string Horas_Matutinas(string cedula, DateTime desde, DateTime hasta)
    {
        string respuesta = "";
        DateTime resto = Convert.ToDateTime("00:00:00");
        //Llamo la conexion SQL
        SqlConnection Wdcon_usuario = new SqlConnection(WDcon);
        SqlCommand usuario = new SqlCommand();
        SqlDataReader usuarioDR = null;
        TimeSpan tiempo = Convert.ToDateTime("00:00:00") - Convert.ToDateTime("00:00:00");
        //Instancio la conexion SQL
        usuario.Connection = Wdcon_usuario;

        //Registro el Query SQL
        usuario.CommandText = "SELECT * FROM matutino WHERE " +
        "(cedula = @ID) AND " +
        "(desde >= @DESDE) AND " +
        "(hasta <= @HASTA)";
        usuario.Parameters.AddWithValue("@ID", Convert.ToInt64(cedula));
        usuario.Parameters.AddWithValue("@DESDE", Convert.ToDateTime(desde));
        usuario.Parameters.AddWithValue("@HASTA", Convert.ToDateTime(hasta));

        //Abro la conexion
        Wdcon_usuario.Open();

        //Ejecuto la consulta
        usuarioDR = usuario.ExecuteReader();

        //Empiezo el ciclo
        while (usuarioDR.Read())
        {
            TimeSpan tiempX = (DateTime)usuarioDR["tiempotrbajado"] - resto;
            tiempo = tiempo + tiempX;
            Double tiemp = Convert.ToDouble(tiempo);
            respuesta = tiempo.ToString("0.00");

        }
        //Cierro la conexion
        Wdcon_usuario.Close();
        //Termino la sentencia SQL

        //int i = 0;
        int total = 8;
        int caracteres = respuesta.Length;
        int restantes = total - caracteres;

        //respuesta.PadLeft(restantes, "0");


        string s = new String('0', restantes) + respuesta;
        return s;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:49:59+00:00Added an answer on May 29, 2026 at 7:49 am

    It looks like you need the difference between two times here, this example might help you out.

    DateTime now = DateTime.Now;
    DateTime later = DateTime.Now.AddHours(2.5);
    double diff = (later - now).TotalHours;
    var x = String.Format("{0:0.00}", diff);
    

    Also, you can create resto and tiempo without using Convert. Instead, you can use:

    DateTime resto = DateTime.Now.Date;
    TimeSpan tiempo = new TimeSpan();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello people I have made a custom title bar for my app. I would
Something that I see people doing all the time is: class Man(object): def say_hi(self):
Let's say I have this sample: page = <html><body><h1 class='foo'></h1><p class='foo'>hello people<a href='http://'>hello world</a></p></body></html>
Hello people of StackOverflow! I have used the searrch option, I've found some related
Hello people i stick on a problem i have a header with no zoom
Hello people of stackoverflow. I have a problem. I'm trying to set up my
Hello again Stackoverflow people! Assume I have these words: smartphones, smartphone I want to
Hello people from stackoverflow I have found more IE7 problems (tested in compatibility mode
Hello people is it true that we cannot integrate Saxon with Visual Studio? Because
Hello people of Stackoverflow! I have been going through the Mozilla Developer Network's JavaScript

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.