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

x
?
Solved

Convert sybase datetime to time in seconds since unix epoch

Posted on 2007-03-27
6
Medium Priority
?
7,660 Views
Last Modified: 2012-06-22
Hi Guys

I am looking for a way to convert master..sysdatabases columns: crdate and dumptrdate into seconds since the UNIX epoch.  Perferably I would like the databases to do this but failing that a C/C++ function that does it

Thanks
0
Comment
Question by:Grant Rogers
[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
  • 2
  • 2
  • 2
6 Comments
 
LVL 10

Accepted Solution

by:
bret earned 252 total points
ID: 18800557
The TSQL datediff function is probably the place to start, you can get the difference between any two dates in various units, including seconds.  You will  then need to make adjustments for the difference between the time zone the date is from and UTC.  And adjustments for whether the date was affected by daylight savings time or not.  Note that ASE doesn't store any information about time zone or daylight savings time, and the environment ASE ran under may have changed over time (i.e. from one time zone to another if corporate headquarters moved, etc.), so you may need to gather some historical metaknowledge about the server's history to get a correct result.  I don't think the datediff function makes any adjustments for leap seconds, either.

(I recommend running ASE servers in a UTC environment, making clients responsible for any conversions to their local timezone).
0
 
LVL 3

Assisted Solution

by:knel1234
knel1234 earned 248 total points
ID: 18804017
select datediff(ss, sd.crdate, sd.dumptrdate)
    from sysdatabases sd

I am able to retrieve the seconds between the 2 timestamps.
36495950
36407822
11106342
Command has been aborted.

Unfortunately, the problem is that the crdate will often default to 1/1/1900.
This causes a 535 error and the Command has aborted message above.

It is important to remember that datediff produces results of datatype int, and causes errors if the result is greater than 2,147,483,647.
1)For seconds, this is 68 years, 19 days, 3:14:07 hours.
2)For milliseconds, this is approximately 24 days, 20:31.846 hours.

cheers
knel
0
 
LVL 3

Expert Comment

by:knel1234
ID: 18804052


FYI

I added my thoughts just for another point of view.  However, you should be mindful of Brets comments.  
In addition, this year (2007) is perfect example of potential issues relating to daylight savings time.

You might want to rethink the question.  What question(s) are you really trying to answer?

cheers
knel
0
Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

 

Author Comment

by:Grant Rogers
ID: 18806572
Thanks guys that information is very usful, it also explains why they take the epoch from 1900 in this function:

(Taken from)
http://cvs.zope.org/Products/ZSybaseDA/src/ctsybase.c?rev=1.3

#define EPOCH_DAYS_SINCE_1900     25567
#define SYBASE_TICKS_PER_SECOND     300
#define SECONDS_PER_DAY           86400

/*****************************************************************************
 *                                                                           *
 * CS_DATETIMEToTimestamp : convert a time in CS_DATETIME format to a        *
 *                          unix timestamp                                   *
 *                                                                           *
 * Arguments:                                                                *
 *        date - the date in CS_DATETIME format                              *
 *                                                                           *
 * Remarks:                                                                  *
 *                                                                           *
 ****************************************************************************/

static time_t
CS_DATETIMEToTimestamp (CS_DATETIME date)
{
  return ((date.dtdays - EPOCH_DAYS_SINCE_1900) * SECONDS_PER_DAY) +
    (date.dttime / SYBASE_TICKS_PER_SECOND);
}

Can anyone confirm this function is correct?
0
 
LVL 10

Expert Comment

by:bret
ID: 18812035
Well, assuming that the CS_DATETIME is a UTC value, it is certainly close, but I'd be careful making that assumption.   It doesn't make any adjustments for leap seconds, though (but then, I don't know if UNIX time does either).
0
 

Author Comment

by:Grant Rogers
ID: 18814862
Well I got it working thanks for you help guys
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

609 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