0

I am querying an oracle database which has a column "Start".

My query returns a 10 digit integer in this column:

1369423190
1369423574
1369424520

My problem is converting these values back to a datetime in c#

start = reader.GetInt64(17);
dt = new DateTime(start);
strStart = dt.ToString();

This code is currently returning the following values for strStart:

1/1/0001 12:02:16 AM
1/1/0001 12:02:16 AM
1/1/0001 12:02:16 AM

What am I doing wrong here?

*Update*

I updated my code but the results are a bit off:

var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
l = (long)reader.GetInt64(17);
epoch = epoch.AddSeconds(l);
Start = epoch.ToString();

10/15/2056 2:46:04 PM
10/7/2273 7:46:20 PM
12/15/2403 12:21:01 PM
jmyns
  • 127
  • 10

2 Answers2

1

The number stored in the database is in Unix Time, the number of seconds since 1/1/1970 12:00:00 AM. The .Net DateTime constructor you are using take ticks, which are the number of 100ns intervales since 1/1/0001 12:00:00 AM.

So you need to convert from Unix time to .NET. See How do you convert epoch time in C#? for an answer.

Community
  • 1
  • 1
shf301
  • 31,086
  • 2
  • 52
  • 86
0

Try this:

var yourTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(1369423190).ToLocalTime();
ducmami
  • 215
  • 1
  • 2