How to convert a Decimal value to Datetime?

Asked

Viewed 1,608 times

2

Can anyone help me with the following question?

I have returns of two variables. Examples:

  • 1st - of the type decimal (vdecTotalHoras) and the
  • 2nd - also of the type decimal (vdecMediaAnalise), both return date and time values in decimal. How do I convert to DateTime?

The code below demonstrates how I am receiving the values:

(
    decTotalHoras = ((paintHoras * 60) + paintMinutos) / 60;
    decMediaAnalise = (decTotalHoras) / paintAnalises;
)

But I can’t convert the returns to Hour/Minute/Second.

  • 1

    I don’t understand your question. Say your problem more clearly, where do you want to go, and if possible what you tried to do. Do you have the amount of seconds? For me these variables that used in the example are very loose, without context. Enjoy explain what is return to you, since variable does not return anything, they only have values.

  • You are working only hours and minutes. It doesn’t make much sense to use a DateTime. I think your case would be more like a TimeSpan.

1 answer

0


I think what would make more sense is the conversion to a Time gap (TimeSpan). If so you can use the section below:

TimeSpan.FromHours(Convert.ToDouble(decimalValue));

Otherwise you can try the following:

Convert.ToDateTime(decimalValue);

But I never used the second form and I don’t know how she would behave.

  • Thanks for the tip, I covered my variable in Timespan and it worked.

  • If it worked do not forget to signal as answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.