0

HI:
I need to convert a bigint filed in database to equivalent datatime
i couldn't do this from sqlserver nor visual studio
i have tried ticks but its not useful any idea? thanks alot

Abd
  • 426
  • 1
  • 8
  • 27
  • Please post examples of the bigint values in your database – Anthony Faull Nov 24 '10 at 13:31
  • A useful date format for bigint might be "yyyymmddhhmmssmmm". It would be sortable and human readable. – Anthony Faull Nov 24 '10 at 13:38
  • the values in the database looks:1276162464406 and 1277290809250 but I don't know the equivalent values in datetime I have just arrived here, and theses don't look like ticks – Abd Nov 25 '10 at 06:46

1 Answers1

0

Why not just like in SQL Server: get minutes and add them to (dateTime.AddMinutes) to 1900-01-01 ?

Convert .NET Ticks to SQL Server DateTime

(we know that at 1900-01-01 ticks count was 599266080000000000)

        long tNow = 634024345696365272;
        long t1900 = 599266080000000000;

        double minutes = (tNow - t1900) * Math.Pow((double)10,-7) / 60;
        var dataTime = DateTime.Parse("1900-01-01").AddMinutes(Math.Round(minutes));
Community
  • 1
  • 1
Roman Pokrovskij
  • 9,449
  • 21
  • 87
  • 142