[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 418
  • Last Modified:

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

Thanks in advance...
0
prodier
Asked:
prodier
  • 3
  • 2
1 Solution
 
AerosSagaCommented:
how are you getting that date from 1092737700?
0
 
gregoryyoungCommented:
DATEADD(SECOND, columnname, '01/01/1970') AS expr1
0
 
gregoryyoungCommented:
unix timestamps are seconds since standard epoch.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
AerosSagaCommented:
yuck, lol
0
 
gregoryyoungCommented:
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
 
ihenryCommented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now