I need to add one day in input date value when formatting
for output field. Does any existing built-in function
provide the facility?
Do I have to develop a custom code? Does anyone have sample
custom code.
Thanks
Aftab
This should work (below)
since you didn't specify, I made some assumptions on format
I also assume that the input is a date and not some type of
string or other group of numbers
Using Julian avoids needing to do leap year and month length
calculations...
Let me know how it goes..
// assume valid input date in hl7 format "YYYYMMDD[hhmmss]"
// return just date portion "YYYYMMDD"
//
string szTemp;
int iYear, iDay;
if ( pb->size() < 8 )
return 1;
pb->truncate(8);
fmtDate( pb, mode, "%Y%j", "YYYYMMDD"); // convert to
julian
szTemp = *pb; // isolate Year as integer
szTemp[4] = 0;
iYear = szTemp;
szTemp = *pb; // isolate Day as integer
szTemp.offsetCopy(szTemp, 4);
iDay = szTemp;
iDay = iDay + 1; // add a day
pb->set( "" + iDay); // set blob to day
justify( pb , mode , "R03" ); // add zeroes
pb->paste(0, "" + iYear ); // include year
fmtJulian( pb, mode, "%Y%m%d" );
if (pb->size() < 8) // failed - end of year?
{
szTemp = iYear + 1;
pb->set(szTemp + "0101");
}
return 1;
Thank you for the help, yes it works perfectly. I made a
little modification to the code because my input is six
digit date (yymmdd). Here is modified code
string szTemp;
int iYear, iDay, mYear;
szTemp = *pb; // isolate Year as integer
szTemp[2] = 0;
mYear = szTemp;
szTemp = *pb;
if (mYear > 50)
{
pb->set("19" + szTemp);
}
else
pb->set("20" + szTemp);
pb->truncate(8);
fmtDate( pb, mode, "%Y%j", "YYYYMMDD"); // convert to
julian
szTemp = *pb; // isolate Year as integer
szTemp[4] = 0;
iYear = szTemp;
szTemp = *pb; // isolate Day as integer
szTemp.offsetCopy(szTemp, 4);
iDay = szTemp;
iDay = iDay + 1; // add a day
pb->set( "" + iDay); // set blob to day
justify( pb , mode , "R03" ); // add zeroes
pb->paste(0, "" + iYear ); // include year
fmtJulian( pb, mode, "%Y%m%d" );
if (pb->size() < 8) // failed - end of year?
{
szTemp = iYear + 1;
pb->set(szTemp + "0101");
}
return 1;
Thanks again
Aftab
Aftab
Which is dealt with at the end of the code
-
if the day was 31 - that would be Jan 31
Adding one is 32 - Which is Feb 1
it also does leap year for you ..
Consider the field's usage,
if what you need is a date plus one (tomorrow)
I'd guess the year always starts with a "20"
however, if things vary; try this code:
input is YYMMDD
output is YYYYMMDD
[includes notes on making the output YYMMDD]
the main "trick" is changes to this line:
fmtDate( pb, '\004', "%Y%j", "YYMMDD");
the "YYMMDD" specifies the input will be a 2 character year
the '\004' specifies using the Impact! solution for Y2K
it will assume "19" for "86" and "20" for "09"
--- code starts --------------------
string szTemp;
int iYear, iDay;
if ( pb->size() < 6 )
return 1;
pb->truncate(6);
fmtDate( pb, '\004', "%Y%j", "YYMMDD"); // convert to julian
day
szTemp = *pb; // isolate Year as integer
szTemp[4] = 0;
iYear = szTemp;
szTemp = *pb; // isolate Day as integer
szTemp.offsetCopy(szTemp, 4);
iDay = szTemp;
iDay = iDay + 1; // add a day
pb->set( "" + iDay); // set blob to day
justify( pb , mode , "R03" ); // add zeroes
pb->paste(0, "" + iYear ); // include year
fmtJulian( pb, mode, "%Y%m%d" ); // %y for two digit year
if (pb->size() < 8) // end of year - change to 6 for two
digit year