?
Solved

Convert Unix Time Stamp

Posted on 2004-08-18
6
Medium Priority
?
414 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
[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
  • Learn & ask questions
  • 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 2000 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
Independent Software Vendors: 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!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

777 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