• Introducing Dark Mode! Switch by clicking on the lightbulb icon next to Search or by clicking on Default style at the bottom left of the page!

Find Previous Year Date from cureent year Date

Kishore03

Active Member
Hi

How can i find previous year date from current year date?

Example:Current year date is 10/23/2014.I want to retrieve the previous year date (10/23/2013).Is there any business function or system function available to calculate the date in JDE?


Thanks
 

BOster

Legendary Poster
I think you could create a C BSFN to do this pretty easily if one doesn't all ready exist.

Code:
AdvanceDate(&lpDS->jdDateOut, &lpDS->jdDateIn, -12, 0);
OR

Code:
AdvanceDate(&lpDS->jdDateOut, &lpDS->jdDateIn, lpDS->nMonthsToAdvance, 0);
What do you want for a return if the date is Feb 29 (Feb 28 or Mar 1)? Dates all ways seem to be more confusing than they first appear. Here is a utility function I wrote that I use quite a bit for rolling date and time that might give some insight:

Code:
#ifndef DATASTRUCTURE_D5800034C
#define DATASTRUCTURE_D5800034C

typedef struct tagDSD5800034C
{
  JDEDATE           jdDateIn;                            
  MATH_NUMERIC      mnTimeIn;                            
  JDEDATE           jdDateOut;                           
  MATH_NUMERIC      mnTimeOut;                           
  MATH_NUMERIC      mnRollYears;                         
  MATH_NUMERIC      mnRollMonths;                        
  MATH_NUMERIC      mnRollDays;                          
  MATH_NUMERIC      mnRollHours;                         
  MATH_NUMERIC      mnRollMinutes;                       
  MATH_NUMERIC      mnRollSeconds;                       
} DSD5800034C, *LPDSD5800034C;
 
#define IDERRjdDateIn_1                           1L
#define IDERRmnTimeIn_2                           2L
#define IDERRjdDateOut_3                          3L
#define IDERRmnTimeOut_4                          4L
#define IDERRmnRollYears_5                        5L
#define IDERRmnRollMonths_6                       6L
#define IDERRmnRollDays_7                         7L
#define IDERRmnRollHours_8                        8L
#define IDERRmnRollMinutes_9                      9L
#define IDERRmnRollSeconds_10                     10L

#endif


JDEBFRTN (ID) JDEBFWINAPI AcmeRollDateTime (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5800034C lpDS)  
 
{ 
   /************************************************************************ 
    *  Variable declarations 
    ************************************************************************/ 
	JDEDATE	jd;
	long	ryr=0,rmth=0,rday=0,rhr=0,rmin=0,rsec=0,h,m,s,x;
 
   /************************************************************************ 
    * Check for NULL pointers 
    ************************************************************************/ 
   if ((lpBhvrCom == (LPBHVRCOM) NULL) || 
       (lpVoid    == (LPVOID)    NULL) || 
       (lpDS      == (LPDSD5800034C)	NULL)) 
   { 
     jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL); 
     return ER_ERROR; 
   } 
 
   /************************************************************************ 
    * Main Processing 
    ************************************************************************/ 
	MathNumericToLong(&lpDS->mnRollYears,	&ryr);
	MathNumericToLong(&lpDS->mnRollMonths,	&rmth);
	MathNumericToLong(&lpDS->mnRollDays,	&rday);
	MathNumericToLong(&lpDS->mnRollHours,	&rhr);
	MathNumericToLong(&lpDS->mnRollMinutes,&rmin);
	MathNumericToLong(&lpDS->mnRollSeconds,&rsec);

	/***** roll time *****/
	I5800034_BreakDownTime(&lpDS->mnTimeIn, &h, &m, &s);

	/* seconds */
	s += rsec;
	x = s / 60;
	rmin += x;
	s -= (x * 60);
	if(s < 0)
	{
		s += 60;
		rmin--;
	}

	/* min */
	m += rmin;
	x = m / 60;
	rhr += x;
	m -= (x * 60);
	if(m < 0)
	{
		m += 60;
		rhr--;
	}

	/* hour */
	h += rhr;
	x = h / 24;
	rday += x;
	h -= (x * 24);
	if(h < 0)
	{
		h += 24;
		rday--;
	}

	IntToMathNumeric((h * 10000) + (m * 100) + s, &lpDS->mnTimeOut);
	

	/***** roll date *****/
	rmth += ryr * 12;
	//AdvanceDate(&lpDS->jdDateOut, &lpDS->jdDateIn, rmth, rday);		debug, this doesnt work as expected

	/* the documentation is at best confusing for Advancedate, passing both rmth and rday on single call does not produce
	   expected results.  Passing 0 for month and rday for days should work and appears to be working
		in other places in custom code.  However I am a little concerned, so I am going to use AdvanceOneDay/DecrementOneDay
		api in this function.  May be a little slower, but I feel more comfortable with what the API is doing.
	 */
	//if(rday != 0)		debug, following if,else should work but.... documentation is not clear
	//	AdvanceDate(&jd, &lpDS->jdDateIn, 0, rday);
	//else
	//	jd = lpDS->jdDateIn;

	jd = lpDS->jdDateIn;

	for(x = 0; x < rday; x++)
		jd = AdvanceOneDay(jd);

	for(x = 0; x < (rday * -1); x++)
		jd = DecrementOneDay(jd);

	if(rmth != 0)
		AdvanceDate(&lpDS->jdDateOut, &jd, rmth, 0);
	else
		lpDS->jdDateOut = jd;
 
   /************************************************************************ 
    * Function Clean Up 
    ************************************************************************/ 
 
   return (ER_SUCCESS); 
} 


static void I5800034_BreakDownTime(LPMATH_NUMERIC pmnTime, long *h, long *m, long *s)
{
	long t;

	MathNumericToLong(pmnTime, &t);
	*h = t / 10000;
	*m = (t / 100) - ((*h) * 100);
	*s = t - (  ((*h) * 10000) + ((*m) * 100)  );

	if(*h > 24 || *h < 0)
		*h = 0;

	if(*m > 60 || *m < 0)
		*m = 0;

	if(*s > 60 || *s < 0)
		*s = 0;
}
 
Last edited:

johndanter

Legendary Poster
Why not just use the add_months expression in ER?

Add (-12) months to your date

Or use the User Date, Format BSFN to split your dates up into D M Y parts (add 1 Y) call it again in the other mode to get the date from the parts

Pass a blank ‘ ‘ to bring back the date from the bits.

Pass a ‘1’ to bring back the bits from the passed in date.
 
Last edited:
Top