Re: RE: Convert String/Number into Julian Date
Naveen,
I Wrote this C function that do the JOB :
Function take as input CYYDDD and return a JDE Date. then you can display in the format you want
Ex : 103001 ---> 01/01/2003 (JDEDate)
Christian
PS : This code was based on a JDE Function that was incomplete for our needs and I don't remember the original BSFN Number.
-----------------------------------------------------
JDEBFRTN (ID) JDEBFWINAPI PWCConvertJulianDateToJDEDate (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD58001 lpDS)
{
/************************************************************************
* Variable declarations
************************************************************************/
int uMonth = 1 ;
int uYears = 0 ;
int uJulianDays = 0 ;
int uIsLeapYear = 0;
int uDaysInMonth[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30,
31, 30, 31 } ;
long uJulianDate = 0L ;
JDEDATE jdWorkDate = { 0, 0, 0 } ;
/************************************************************************
* Declare structures
************************************************************************/
/************************************************************************
* Declare pointers
************************************************************************/
/************************************************************************
* Check for NULL pointers
************************************************************************/
if ((lpBhvrCom == (LPBHVRCOM) NULL) ||
(lpVoid == (LPVOID) NULL) ||
(lpDS == (LPDSD58001) NULL))
{
jdeSetGBRError (lpBhvrCom, lpVoid, (ID) 0, "4363");
return ER_ERROR ;
}
/************************************************************************
* Set pointers
************************************************************************/
/************************************************************************
* Main Processing
************************************************************************/
/*Copie de la date à convertir dans un work field*/
MathNumericToLong ( &lpDS->mnJulianDateInYYYDDD, &uJulianDate ) ;
/*Calcul du nombre d'année et du nombre de jours de la date*/
uYears = (int) (uJulianDate / 1000 ) ;
uJulianDays = (int) (uJulianDate % 1000 ) ;
/*On ajoute 1900 pour obtenir la VRAI année 101 + 1900 = 2001 et 99 + 1900 = 1999*/
jdWorkDate.nYear = (short) (uYears + 1900);
/*Vérification d'une année bissextile*/
if ( (jdWorkDate.nYear > 0) &&
((jdWorkDate.nYear % 4 == 0 && jdWorkDate.nYear % 100 != 0) ||
(jdWorkDate.nYear % 400 == 0)))
{
uIsLeapYear = 1;
}
if ( uJulianDate > 0 && uYears > 0 )
{
/*On commence en Janvier au jour UN*/
jdWorkDate.nMonth = 1 ;
jdWorkDate.nDay = 1 ;
if (uIsLeapYear)
{
uDaysInMonth[2] = 29 ; /* les années bissextile on 29 jours en février*/
}
/*Calcul du mois de la date en cours*/
while (uMonth <= 12 && (uJulianDays > uDaysInMonth[uMonth]))
{
uJulianDays = uJulianDays - uDaysInMonth[uMonth] ;
uMonth = uMonth + 1 ;
}
/*Transfert le jour et le mois dans le Work Date*/
jdWorkDate.nDay = (short) uJulianDays;
jdWorkDate.nMonth = (short) uMonth ;
}
memcpy ( (void *)(&lpDS->jdDateConverted),
(const void *)(&jdWorkDate), sizeof(JDEDATE) ) ;
/************************************************************************
* Function Clean Up
************************************************************************/
return (ER_SUCCESS);
}