Search code examples
.netsqltimeepoch

Convert Unix Epoch Time to Seconds in SQL or .NET


First let me thank you all for your help.

What I need is a function that takes in a EPOCH time stamp, like 1452.235687 and converts it to a readable timestamp like '01-01-1970 00:00:00'. More specifically I only need the time not the date.

If at all possible I would prefer a .NET function instead of a SQL stored procedure. However an SQL stored procedure would work fine as well.

Thank you again,


Solution

  • double EpochSeconds = 1272672608.55;
    DateTime time = new DateTime(1970, 1, 1).AddSeconds(EpochSeconds);
    Console.WriteLine(time);
    

    Prints out:

    5/1/2010 12:10:08 AM
    

    If you just want the time, you can use time.TimeOfDay.