Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

Add one day in output date field

7 posts in General Discussion Last posting was on 2009-10-27 21:35:37.0Z
Aftab Posted on 2009-10-26 19:51:28.0Z
Sender: 392c.4ae5f348.1804289383@sybase.com
From: Aftab
Newsgroups: sybase.public.impact
Subject: Add one day in output date field
X-Mailer: WebNews to Mail Gateway v1.1t
Message-ID: <4ae5fdc0.3b77.1681692777@sybase.com>
NNTP-Posting-Host: 10.22.241.41
X-Original-NNTP-Posting-Host: 10.22.241.41
Date: 26 Oct 2009 11:51:28 -0800
X-Trace: forums-1-dub 1256586688 10.22.241.41 (26 Oct 2009 11:51:28 -0800)
X-Original-Trace: 26 Oct 2009 11:51:28 -0800, 10.22.241.41
Lines: 12
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.impact:2210
Article PK: 230291

Hi,

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


chris Posted on 2009-10-27 14:21:54.0Z
Sender: 28a7.4ae59fde.1804289383@sybase.com
From: Chris
Newsgroups: sybase.public.impact
Subject: Re: Add one day in output date field
X-Mailer: WebNews to Mail Gateway v1.1t
Message-ID: <4ae70202.6383.1681692777@sybase.com>
References: <4ae5fdc0.3b77.1681692777@sybase.com>
NNTP-Posting-Host: 10.22.241.41
X-Original-NNTP-Posting-Host: 10.22.241.41
Date: 27 Oct 2009 06:21:54 -0800
X-Trace: forums-1-dub 1256653314 10.22.241.41 (27 Oct 2009 06:21:54 -0800)
X-Original-Trace: 27 Oct 2009 06:21:54 -0800, 10.22.241.41
Lines: 65
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.impact:2211
Article PK: 230290

I've had to write things like this in the past because the
builtin isn't there

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;

> Hi,
>
> 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