Convert float, double or single value to Datetime

Asked

Viewed 482 times

0

I was having trouble Cast when running a lambda and serializing for the service. Well, the solution was to pass everything to String and I got it. On the other side(Android App) I pick up and do what has to be done. Well, it turns out that this customer has his dates loaded into the bank like a float, like this one(79018). Turns out when I give one float.Parse(data_string) and then a Convert.ToDateTime(floatvalue), gives the casting error saying that can not do the cast of Double for Single. If I put for single, the error continues, the same problem I was having before, which generated me some posts here. How I transform this value into Datetime?

private void listaLibera_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            var libera = e.SelectedItem as Liberacao;
            DateTime datas = Convert.ToDateTime(float.Parse(libera.DataLib));

            lblTipoVenda.Text = "Tipo de Venda: " + libera.TipoVenda;
            //lblVencimento.Text = "Vencimento: " + (Convert.ToDateTime(libera.Vendedor)).ToString("dd/mm/yyyy");
            lblJuros.Text = "Juros: " + libera.Juros.ToString();
            lblEntrada.Text = "Entrada: " + libera.Entrada;
            lblAcrescimo.Text = "Acréscimo: " + libera.Acrescimo;
            lblDesconto.Text = "Desconto: " + datas.ToString("dd/mm/yyyy");
        }

I took the literal value and tried to convert and continues the error of cast, thus: Convert.ToDateTime(79018.0f).

  • You need to see the code, the means to reproduce the problem. I don’t think I’ve ever seen a database as badly structured as this one. I’ve seen one before that the columns were all bad words that caused less trouble than this.

  • I have been having this Cast problem for a long time. I had to do a Ambi to continue my work. Whenever I loaded a float or double value of the bank and when I assigned the property in my DTO, I gave this error and did not solve it. What I did was pass everything to string and so I could continue, but it’s not what I wish, but I had to do so

  • Their system was developed in Clarion and I think that’s why it’s in numerical form and not in date format and has been around for over 15 years.

  • I can’t do that inside the Xamarin.Forms: var datas = DateTime.FromOADate(meu_double). Does not recognize the Fromoadate

  • Is this date not in millisecond format? If so, try var time = Timespan.Frommilliseconds(milliseconds);

  • @Grupocdsinformática, I can’t say, but if you do it in the comic book: convert(datetime, 79018-36163) as DataLib I get it: 2017-05-02 00:00:00.000. 79018 is equivalent to the field DataLib

  • @pnet looks that gist, it explains why of the calculation. I think the way will be more or less this. I will put a code as answer to see if it helps.

Show 2 more comments

1 answer

1


According to this gist, the date in Clarion considers the number of days that have passed since 28/12/1800. Then following logic, will give the date as follows:

new DateTime(1800, 12, 28).AddDays(79018).ToShortDateString();

Correct me if I’m wrong, please.

  • I’m gonna take this test and as soon as I get the results, I’ll put.

  • On the fly, CDS Informatics. Problem solved. I was starting to read something about the Clarion, but I appreciate the anticipation.

Browser other questions tagged

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