x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 420

# Convert Unix Time Stamp

Hello,

I have a table in a SQL Server 2000 Database. One of the columns holds Unix Time Stamp values. Is there a way to convert the time stamp to a viewer friendly version?

ie:

1092737700

to

08 / 17 / 2004

0
prodier
• 3
• 2
1 Solution

Commented:
how are you getting that date from 1092737700?
0

Commented:
0

Commented:
unix timestamps are seconds since standard epoch.
0

Commented:
yuck, lol
0

Commented:
if you wanted to do it in code the operation would be the same ...

to GET a unix timestamp from a Date ...

static private int UnixTimeStamp(DateTime d) {
TimeSpan t = d.Subtract(DateTime.Parse("1/1/1970"));
return (int) Math.Floor(t.TotalSeconds) ;
}
0

Commented:
Helo,

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// calendar reference, at
// http://pumas.jpl.nasa.gov/PDF_Examples/04_21_97_1.pdf
const int NumDaysTo10000 = 3652059;
const int NumDaysTo1970 = 719162;

const long NumTicksPerDay = 864000000000;
const long NumTicksPerSecond = 10000000;

const long MaxTicks = NumDaysTo10000 * NumTicksPerDay -1;
const long MinTicks = 0;

// number of 100 nanosecond units from 1/1/1601 to 1/1/1970
Int64 TicksTo1970   = NumDaysTo1970 * NumTicksPerDay;

// number of seconds elapsed in Unix epoch timestamp
int elapsedEpoch = 1092737700;

// number of 100 nanosecond units from 1/1/1970 to now
Int64 TicksFrom1970 = elapsedEpoch * NumTicksPerSecond;

long universalTicks = TicksTo1970 + TicksFrom1970;
DateTime univDT = new DateTime(universalTicks);

// display elapsedEpoch in UTC
Console.WriteLine(univDT);

TimeZone tz = TimeZone.CurrentTimeZone;
long localTicks = universalTicks + tz.GetUtcOffset(univDT).Ticks;

if ((ulong)localTicks>(ulong)MaxTicks)
{
if (localTicks>MaxTicks)
localTicks = MaxTicks;
else
localTicks = MinTicks;
}

// Display in local time
Console.WriteLine( new DateTime(localTicks) );
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

This site provides unix timestamp to readable timestamp
http://www.onlineconversion.com/unix_time.htm

Conversely,
http://www.unixtimestamp.com/index.php

HTH
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.