Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Convert Unix Time Stamp

Posted on 2004-08-18
Medium Priority
417 Views
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
Question by:prodier
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 2

LVL 17

Expert Comment

ID: 11832945
how are you getting that date from 1092737700?
0

LVL 37

Accepted Solution

gregoryyoung earned 2000 total points
ID: 11833912
0

LVL 37

Expert Comment

ID: 11833924
unix timestamps are seconds since standard epoch.
0

LVL 17

Expert Comment

ID: 11833954
yuck, lol
0

LVL 37

Expert Comment

ID: 11833991
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

LVL 20

Expert Comment

ID: 11840112
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

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
###### Suggested Courses
Course of the Month11 days, 15 hours left to enroll