Avatar of Grant Rogers
Grant RogersFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

Convert sybase datetime to time in seconds since unix epoch

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
Sybase Database

Avatar of undefined
Last Comment
Grant Rogers
ASKER CERTIFIED SOLUTION
Avatar of bret
bret
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of knel1234
knel1234
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of knel1234
knel1234
Flag of United States of America image



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
Avatar of Grant Rogers
Grant Rogers
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

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?
Avatar of bret
bret
Flag of United States of America image

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).
Avatar of Grant Rogers
Grant Rogers
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Well I got it working thanks for you help guys
Sybase Database
Sybase Database

Sybase, a subsidiary of SAP, builds a client/server relational database management system. Products include Adaptive Server Enterprise (ASE), Adaptive Server Anywhere (ASA), Sybase Unwired Platform (SUP) for mobile applications, Afaria for enterprise mobile device management and IQ for data warehouse and big data applications.

5K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo