Command similar to sql Convert in c#

Asked

Viewed 77 times

0

I have a return in sql that comes as something like 52,451541554.

That return, if I convert it with the command convert(datetime, DtCriacao, 103) of sql it turns into a date format, only that I’m needing to pick up that same one, which this time came from an excel file and convert it to date format or string.

I have no idea how to do this kind of conversion in c#.

Thank you

  • 52,451541554 this value is just the hours? minutes? you want to add to the current date??

  • 05/09/2017 16:15... that’s what he is

  • in case it is a timestamp!?

  • I believe so

1 answer

1


Whereas the value received from comic is a timestamp, you need to convert it into date and then display in the format corresponding to the 103 of sql (dd/mm/yyyy):

string valorSql = "52,451541554";
System.DateTime data = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
data = data.AddSeconds(valorSql);
string retorno = data.ToString("dd/M/yyyy", CultureInfo.InvariantCulture);
  • Who is this datetime?

  • oops, my mistake. I changed the answer

  • Dude, he’s returning me 01/01/1970 12:57:24

  • convert(datetime, DtCriacao, 103) this is the code you would use in sql. Who is datetime (current date? ) and DtCriacao (that value?) ??

  • datetime -> type and dt creation my 52.45...

  • I asked why running the code select convert(datetime, '52451541554', 103) gives me an error (Conversion failed when converting date and/or time from character string.)

  • Rotate "42983,6773691319" in place of '52451541554'

  • 1

    Small change of answer but found the solution based on what he passed double sla = Double.Parse(xlworksheet2.Range["B4"]. Formulalocal); Datetime date = new Datetime(1900, 1, 1). Adddays(sla - 2);

Show 4 more comments

Browser other questions tagged

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