Solved

Convert Unix Time Stamp

Posted on 2004-08-18
6
406 Views
Last Modified: 2008-02-01
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
Comment
Question by:prodier
  • 3
  • 2
6 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11832945
how are you getting that date from 1092737700?
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 11833912
DATEADD(SECOND, columnname, '01/01/1970') AS expr1
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11833924
unix timestamps are seconds since standard epoch.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 17

Expert Comment

by:AerosSaga
ID: 11833954
yuck, lol
0
 
LVL 37

Expert Comment

by:gregoryyoung
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

by:ihenry
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now