Editing portions of DATE field to compose a date value2019 Community Moderator ElectionHow to return only the Date from a SQL Server DateTime datatypeCompare two dates with JavaScriptAdd days to JavaScript DateWhere can I find documentation on formatting a date in JavaScript?Detecting an “invalid date” Date instance in JavaScriptHow do I get the current date in JavaScript?Calculate difference between two dates (number of days)?How to format a JavaScript dateGet current time and date on AndroidConvert string of length 8 to *EUR date for comparing

Do I need life insurance if I can cover my own funeral costs?

How to make healing in an exploration game interesting

Does this AnyDice function accurately calculate the number of ogres you make unconcious with three 4th-level castings of Sleep?

PTIJ: Who should pay for Uber rides: the child or the parent?

The use of "touch" and "touch on" in context

What has been your most complicated TikZ drawing?

Why must traveling waves have the same amplitude to form a standing wave?

How to deal with taxi scam when on vacation?

How do anti-virus programs start at Windows boot?

Did CPM support custom hardware using device drivers?

Dot in front of file

Replacing Windows 7 security updates with anti-virus?

Official degrees of earth’s rotation per day

What is this large pipe coming out of my roof?

Is a lawful good "antagonist" effective?

Current sense amp + op-amp buffer + ADC: Measuring down to 0 with single supply

Using "wallow" verb with object

Good allowance savings plan?

What is IP squat space

Can anyone tell me why this program fails?

Instead of Universal Basic Income, why not Universal Basic NEEDS?

What are the possible solutions of the given equation?

Possible Leak In Concrete

Why do passenger jet manufacturers design their planes with stall prevention systems?



Editing portions of DATE field to compose a date value



2019 Community Moderator ElectionHow to return only the Date from a SQL Server DateTime datatypeCompare two dates with JavaScriptAdd days to JavaScript DateWhere can I find documentation on formatting a date in JavaScript?Detecting an “invalid date” Date instance in JavaScriptHow do I get the current date in JavaScript?Calculate difference between two dates (number of days)?How to format a JavaScript dateGet current time and date on AndroidConvert string of length 8 to *EUR date for comparing










0















When using RPGLE's %date() function I can "converte" a string displaying a date like '2019-01-01' via %date('2019-01-01':*ISO) or '20190202' via %date('20190202':*ISO0) into a date field.



dcl-s dateISO date(*ISO);

dateISO = %date('2019-01-01':*ISO);
dsply dateISO;
dateISO = %date('20190202':*ISO0);
dsply dateISO;


On my current database date values are split up into 3 (sometimes 4) different fields rather than stored in fields defined as 'date': On for the day part, one for the month and 1 or 2 (depends on the age of the database file) fields for either the year as 4 digit or one field for the 2 digit century and one for the 2 digit year (2019 -> stored as '2019' or '20' and '19')



In my beginning, I leard to group the 3 zoned date fields with a data structure and use the overlaying "date-subfield" for my DDS (DSPF/PRTF) or "working with dates".
I "discovered" for myself the beauty of DATE fields and that I can use the %date() BIF to convert the data structure subfield, which represents the full date, to my needed date field. But for reasons, I don't want to create a new data structure for each "new" date.



So like using %subdt() for extracting portions of a DATE or TIMESTAMP I hoped that I can edit a portion of a DATE field.



Does anyone know how to do it?



Edit:



To all those who thougt I want to GET a portion of a date: NO, I just want to EDIT (as written in the headline) a portion of the date. Like I have a DDS PF definition like this:



 A R TESTPFR
A
A T1NUMB 6S 0 TEXT('Some number')
A T1TEXT 10A TEXT('Some text')
A T1DTDD 2S 0 TEXT('Day part')
A T1DTMM 2S 0 TEXT('Month part')
A T1DTYY 4S 0 TEXT('Year part')


My "old" way was like this:



**free
ctl-opt decedit('0,') datedit(*dmy) dftactgrp(*no) option(*nodebugio:*srcstmt:*nounref);

dcl-f testpf disk; // Database File

dcl-ds dateDS qualified; // DS for "converting"
date zoned(8) pos(1);
day zoned(2) pos(1);
month zoned(2) pos(3);
year zoned(4) pos(5);
end-ds;
dcl-s dateISO date(*ISO); // Destination Date field
dcl-ds testpfrDS likerec(testpfr); // Record definition if the database file


read testpfr testpfrDS;
dow (not %eof(testpf));
dateDS.day = testpfrDS.t1dtdd ; //t1dtdd is the day field
dateDs.month = testpfrDS.t1dtmm; //t1dtdd is the month field
dateDs.year = testpfrDS.t1dtyy; //t1dtdd is the year field

dateISO = %date(dateDS.date:*EUR);
dsply dateISO; // Work with the date

read testpfr testpfrDS;
enddo;

*inlr = *on;


This ment that I had to define a data structure in each new program, put the PF fields into the subfields and convert the overlaying subfield. In this case this was not that much overhead. But when having DSPF involved where the use input a range of date, I had to write a DS for the FROM date, the TO date and the date from the database. Ok I admit that I could make it like above, just make one DS and use this for the three dates. But my hope was that I can just define a date field and code someting like this:



%subdt(dateISO:*day) = testpfrDS.t1dtdd;
%subdt(dateISO:*month) = testpfrDS.t1dtmm;
%subdt(dateISO:*year) = testpfrDS.t1dtyy;


So I don't have to built a DS for the date conversion every time.



But as @jmarkmurphy answered, I now came up with the solution of having a DS with the three/four date subfields and one overlaying subfield which is defined as DATE, so I dnon't have to use %date()










share|improve this question
























  • I don't exactly follow what you're asking. Can you provide an example of what you want to accomplish?

    – jtaylor___
    Mar 7 at 13:55















0















When using RPGLE's %date() function I can "converte" a string displaying a date like '2019-01-01' via %date('2019-01-01':*ISO) or '20190202' via %date('20190202':*ISO0) into a date field.



dcl-s dateISO date(*ISO);

dateISO = %date('2019-01-01':*ISO);
dsply dateISO;
dateISO = %date('20190202':*ISO0);
dsply dateISO;


On my current database date values are split up into 3 (sometimes 4) different fields rather than stored in fields defined as 'date': On for the day part, one for the month and 1 or 2 (depends on the age of the database file) fields for either the year as 4 digit or one field for the 2 digit century and one for the 2 digit year (2019 -> stored as '2019' or '20' and '19')



In my beginning, I leard to group the 3 zoned date fields with a data structure and use the overlaying "date-subfield" for my DDS (DSPF/PRTF) or "working with dates".
I "discovered" for myself the beauty of DATE fields and that I can use the %date() BIF to convert the data structure subfield, which represents the full date, to my needed date field. But for reasons, I don't want to create a new data structure for each "new" date.



So like using %subdt() for extracting portions of a DATE or TIMESTAMP I hoped that I can edit a portion of a DATE field.



Does anyone know how to do it?



Edit:



To all those who thougt I want to GET a portion of a date: NO, I just want to EDIT (as written in the headline) a portion of the date. Like I have a DDS PF definition like this:



 A R TESTPFR
A
A T1NUMB 6S 0 TEXT('Some number')
A T1TEXT 10A TEXT('Some text')
A T1DTDD 2S 0 TEXT('Day part')
A T1DTMM 2S 0 TEXT('Month part')
A T1DTYY 4S 0 TEXT('Year part')


My "old" way was like this:



**free
ctl-opt decedit('0,') datedit(*dmy) dftactgrp(*no) option(*nodebugio:*srcstmt:*nounref);

dcl-f testpf disk; // Database File

dcl-ds dateDS qualified; // DS for "converting"
date zoned(8) pos(1);
day zoned(2) pos(1);
month zoned(2) pos(3);
year zoned(4) pos(5);
end-ds;
dcl-s dateISO date(*ISO); // Destination Date field
dcl-ds testpfrDS likerec(testpfr); // Record definition if the database file


read testpfr testpfrDS;
dow (not %eof(testpf));
dateDS.day = testpfrDS.t1dtdd ; //t1dtdd is the day field
dateDs.month = testpfrDS.t1dtmm; //t1dtdd is the month field
dateDs.year = testpfrDS.t1dtyy; //t1dtdd is the year field

dateISO = %date(dateDS.date:*EUR);
dsply dateISO; // Work with the date

read testpfr testpfrDS;
enddo;

*inlr = *on;


This ment that I had to define a data structure in each new program, put the PF fields into the subfields and convert the overlaying subfield. In this case this was not that much overhead. But when having DSPF involved where the use input a range of date, I had to write a DS for the FROM date, the TO date and the date from the database. Ok I admit that I could make it like above, just make one DS and use this for the three dates. But my hope was that I can just define a date field and code someting like this:



%subdt(dateISO:*day) = testpfrDS.t1dtdd;
%subdt(dateISO:*month) = testpfrDS.t1dtmm;
%subdt(dateISO:*year) = testpfrDS.t1dtyy;


So I don't have to built a DS for the date conversion every time.



But as @jmarkmurphy answered, I now came up with the solution of having a DS with the three/four date subfields and one overlaying subfield which is defined as DATE, so I dnon't have to use %date()










share|improve this question
























  • I don't exactly follow what you're asking. Can you provide an example of what you want to accomplish?

    – jtaylor___
    Mar 7 at 13:55













0












0








0








When using RPGLE's %date() function I can "converte" a string displaying a date like '2019-01-01' via %date('2019-01-01':*ISO) or '20190202' via %date('20190202':*ISO0) into a date field.



dcl-s dateISO date(*ISO);

dateISO = %date('2019-01-01':*ISO);
dsply dateISO;
dateISO = %date('20190202':*ISO0);
dsply dateISO;


On my current database date values are split up into 3 (sometimes 4) different fields rather than stored in fields defined as 'date': On for the day part, one for the month and 1 or 2 (depends on the age of the database file) fields for either the year as 4 digit or one field for the 2 digit century and one for the 2 digit year (2019 -> stored as '2019' or '20' and '19')



In my beginning, I leard to group the 3 zoned date fields with a data structure and use the overlaying "date-subfield" for my DDS (DSPF/PRTF) or "working with dates".
I "discovered" for myself the beauty of DATE fields and that I can use the %date() BIF to convert the data structure subfield, which represents the full date, to my needed date field. But for reasons, I don't want to create a new data structure for each "new" date.



So like using %subdt() for extracting portions of a DATE or TIMESTAMP I hoped that I can edit a portion of a DATE field.



Does anyone know how to do it?



Edit:



To all those who thougt I want to GET a portion of a date: NO, I just want to EDIT (as written in the headline) a portion of the date. Like I have a DDS PF definition like this:



 A R TESTPFR
A
A T1NUMB 6S 0 TEXT('Some number')
A T1TEXT 10A TEXT('Some text')
A T1DTDD 2S 0 TEXT('Day part')
A T1DTMM 2S 0 TEXT('Month part')
A T1DTYY 4S 0 TEXT('Year part')


My "old" way was like this:



**free
ctl-opt decedit('0,') datedit(*dmy) dftactgrp(*no) option(*nodebugio:*srcstmt:*nounref);

dcl-f testpf disk; // Database File

dcl-ds dateDS qualified; // DS for "converting"
date zoned(8) pos(1);
day zoned(2) pos(1);
month zoned(2) pos(3);
year zoned(4) pos(5);
end-ds;
dcl-s dateISO date(*ISO); // Destination Date field
dcl-ds testpfrDS likerec(testpfr); // Record definition if the database file


read testpfr testpfrDS;
dow (not %eof(testpf));
dateDS.day = testpfrDS.t1dtdd ; //t1dtdd is the day field
dateDs.month = testpfrDS.t1dtmm; //t1dtdd is the month field
dateDs.year = testpfrDS.t1dtyy; //t1dtdd is the year field

dateISO = %date(dateDS.date:*EUR);
dsply dateISO; // Work with the date

read testpfr testpfrDS;
enddo;

*inlr = *on;


This ment that I had to define a data structure in each new program, put the PF fields into the subfields and convert the overlaying subfield. In this case this was not that much overhead. But when having DSPF involved where the use input a range of date, I had to write a DS for the FROM date, the TO date and the date from the database. Ok I admit that I could make it like above, just make one DS and use this for the three dates. But my hope was that I can just define a date field and code someting like this:



%subdt(dateISO:*day) = testpfrDS.t1dtdd;
%subdt(dateISO:*month) = testpfrDS.t1dtmm;
%subdt(dateISO:*year) = testpfrDS.t1dtyy;


So I don't have to built a DS for the date conversion every time.



But as @jmarkmurphy answered, I now came up with the solution of having a DS with the three/four date subfields and one overlaying subfield which is defined as DATE, so I dnon't have to use %date()










share|improve this question
















When using RPGLE's %date() function I can "converte" a string displaying a date like '2019-01-01' via %date('2019-01-01':*ISO) or '20190202' via %date('20190202':*ISO0) into a date field.



dcl-s dateISO date(*ISO);

dateISO = %date('2019-01-01':*ISO);
dsply dateISO;
dateISO = %date('20190202':*ISO0);
dsply dateISO;


On my current database date values are split up into 3 (sometimes 4) different fields rather than stored in fields defined as 'date': On for the day part, one for the month and 1 or 2 (depends on the age of the database file) fields for either the year as 4 digit or one field for the 2 digit century and one for the 2 digit year (2019 -> stored as '2019' or '20' and '19')



In my beginning, I leard to group the 3 zoned date fields with a data structure and use the overlaying "date-subfield" for my DDS (DSPF/PRTF) or "working with dates".
I "discovered" for myself the beauty of DATE fields and that I can use the %date() BIF to convert the data structure subfield, which represents the full date, to my needed date field. But for reasons, I don't want to create a new data structure for each "new" date.



So like using %subdt() for extracting portions of a DATE or TIMESTAMP I hoped that I can edit a portion of a DATE field.



Does anyone know how to do it?



Edit:



To all those who thougt I want to GET a portion of a date: NO, I just want to EDIT (as written in the headline) a portion of the date. Like I have a DDS PF definition like this:



 A R TESTPFR
A
A T1NUMB 6S 0 TEXT('Some number')
A T1TEXT 10A TEXT('Some text')
A T1DTDD 2S 0 TEXT('Day part')
A T1DTMM 2S 0 TEXT('Month part')
A T1DTYY 4S 0 TEXT('Year part')


My "old" way was like this:



**free
ctl-opt decedit('0,') datedit(*dmy) dftactgrp(*no) option(*nodebugio:*srcstmt:*nounref);

dcl-f testpf disk; // Database File

dcl-ds dateDS qualified; // DS for "converting"
date zoned(8) pos(1);
day zoned(2) pos(1);
month zoned(2) pos(3);
year zoned(4) pos(5);
end-ds;
dcl-s dateISO date(*ISO); // Destination Date field
dcl-ds testpfrDS likerec(testpfr); // Record definition if the database file


read testpfr testpfrDS;
dow (not %eof(testpf));
dateDS.day = testpfrDS.t1dtdd ; //t1dtdd is the day field
dateDs.month = testpfrDS.t1dtmm; //t1dtdd is the month field
dateDs.year = testpfrDS.t1dtyy; //t1dtdd is the year field

dateISO = %date(dateDS.date:*EUR);
dsply dateISO; // Work with the date

read testpfr testpfrDS;
enddo;

*inlr = *on;


This ment that I had to define a data structure in each new program, put the PF fields into the subfields and convert the overlaying subfield. In this case this was not that much overhead. But when having DSPF involved where the use input a range of date, I had to write a DS for the FROM date, the TO date and the date from the database. Ok I admit that I could make it like above, just make one DS and use this for the three dates. But my hope was that I can just define a date field and code someting like this:



%subdt(dateISO:*day) = testpfrDS.t1dtdd;
%subdt(dateISO:*month) = testpfrDS.t1dtmm;
%subdt(dateISO:*year) = testpfrDS.t1dtyy;


So I don't have to built a DS for the date conversion every time.



But as @jmarkmurphy answered, I now came up with the solution of having a DS with the three/four date subfields and one overlaying subfield which is defined as DATE, so I dnon't have to use %date()







date rpgle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 7:40







Radinator

















asked Mar 7 at 12:31









RadinatorRadinator

1,018632




1,018632












  • I don't exactly follow what you're asking. Can you provide an example of what you want to accomplish?

    – jtaylor___
    Mar 7 at 13:55

















  • I don't exactly follow what you're asking. Can you provide an example of what you want to accomplish?

    – jtaylor___
    Mar 7 at 13:55
















I don't exactly follow what you're asking. Can you provide an example of what you want to accomplish?

– jtaylor___
Mar 7 at 13:55





I don't exactly follow what you're asking. Can you provide an example of what you want to accomplish?

– jtaylor___
Mar 7 at 13:55












3 Answers
3






active

oldest

votes


















2














There is no function that allows you to edit a portion of a date, time or timestamp field. But as you said, you can do so with a data structure. Given that you don't want to create multiple data structures just for the purpose of setting the day value of multiple date fields, you could use a single Based data structure like this:



dcl-ds DateIso Qualified Based(%pDateIso);
year Signed(4:0) Pos(1);
month Signed(2:0) Pos(6);
day Signed(2:0) Pos(9);
end-ds;
dcl-s pDateIso Pointer;

dcl-s startDate Date(*iso);
dcl-s endDate Date(*iso);

pDateIso = %addr(startDate);
DateIso.day = 1;

pDateIso = %addr(endDate);
pDateIso.month = 1;


You could also leverage RPGIV to create a sub-procedure that does what you want.



dcl-proc SetDateDay;
dcl-pi *n Date(*iso);
date Date const;
day Int(5) const;
end-pi

dcl-ds *n;
dateIso Date(*iso);
dateday Signed(2:0) Pos(9);
end-ds;

dateIso = date;
dateday = day;
return dateIso;
end-proc;





share|improve this answer




















  • 1





    If this is what he's asking for, another alternative is to use embedded SQL to pull the day or year from the date: exec sql set :dateDay = Day(:dateIso)

    – Player1st
    Mar 7 at 20:03



















1














I would definitely create a set of procedures to create a Date, Time, or Timestamp from the various parts. To handle the fact that the year might be in two parts, define the fourth "century" parameter as OPTIONS(*NOPASS), and if that's not passed, the procedure would expect the year part to have all four digits.



date = makeDate(dd : mm : yy);
or
date = makeDate(dd : mm : yy: cc);


If you don't want to create a few procedures either, there's actually a way to do this without anything extra:



 date = %date(cc * 1000000 + yy * 10000 + mm * 100 + dd); // untested


But that's some nasty code ...






share|improve this answer






























    0














    Are you asking how you add or substract days, months, years, etc to an RPG date field? I think you may want to peruse the list of RPGLE built-in functions here:
    https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/rzasd/bifs.htm



    If you click on %DAYS for instance, it will lead you to an example here: https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/rzasd/bbmon.htm#bbmon__ebmonths






    share|improve this answer






















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55043879%2fediting-portions-of-date-field-to-compose-a-date-value%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      There is no function that allows you to edit a portion of a date, time or timestamp field. But as you said, you can do so with a data structure. Given that you don't want to create multiple data structures just for the purpose of setting the day value of multiple date fields, you could use a single Based data structure like this:



      dcl-ds DateIso Qualified Based(%pDateIso);
      year Signed(4:0) Pos(1);
      month Signed(2:0) Pos(6);
      day Signed(2:0) Pos(9);
      end-ds;
      dcl-s pDateIso Pointer;

      dcl-s startDate Date(*iso);
      dcl-s endDate Date(*iso);

      pDateIso = %addr(startDate);
      DateIso.day = 1;

      pDateIso = %addr(endDate);
      pDateIso.month = 1;


      You could also leverage RPGIV to create a sub-procedure that does what you want.



      dcl-proc SetDateDay;
      dcl-pi *n Date(*iso);
      date Date const;
      day Int(5) const;
      end-pi

      dcl-ds *n;
      dateIso Date(*iso);
      dateday Signed(2:0) Pos(9);
      end-ds;

      dateIso = date;
      dateday = day;
      return dateIso;
      end-proc;





      share|improve this answer




















      • 1





        If this is what he's asking for, another alternative is to use embedded SQL to pull the day or year from the date: exec sql set :dateDay = Day(:dateIso)

        – Player1st
        Mar 7 at 20:03
















      2














      There is no function that allows you to edit a portion of a date, time or timestamp field. But as you said, you can do so with a data structure. Given that you don't want to create multiple data structures just for the purpose of setting the day value of multiple date fields, you could use a single Based data structure like this:



      dcl-ds DateIso Qualified Based(%pDateIso);
      year Signed(4:0) Pos(1);
      month Signed(2:0) Pos(6);
      day Signed(2:0) Pos(9);
      end-ds;
      dcl-s pDateIso Pointer;

      dcl-s startDate Date(*iso);
      dcl-s endDate Date(*iso);

      pDateIso = %addr(startDate);
      DateIso.day = 1;

      pDateIso = %addr(endDate);
      pDateIso.month = 1;


      You could also leverage RPGIV to create a sub-procedure that does what you want.



      dcl-proc SetDateDay;
      dcl-pi *n Date(*iso);
      date Date const;
      day Int(5) const;
      end-pi

      dcl-ds *n;
      dateIso Date(*iso);
      dateday Signed(2:0) Pos(9);
      end-ds;

      dateIso = date;
      dateday = day;
      return dateIso;
      end-proc;





      share|improve this answer




















      • 1





        If this is what he's asking for, another alternative is to use embedded SQL to pull the day or year from the date: exec sql set :dateDay = Day(:dateIso)

        – Player1st
        Mar 7 at 20:03














      2












      2








      2







      There is no function that allows you to edit a portion of a date, time or timestamp field. But as you said, you can do so with a data structure. Given that you don't want to create multiple data structures just for the purpose of setting the day value of multiple date fields, you could use a single Based data structure like this:



      dcl-ds DateIso Qualified Based(%pDateIso);
      year Signed(4:0) Pos(1);
      month Signed(2:0) Pos(6);
      day Signed(2:0) Pos(9);
      end-ds;
      dcl-s pDateIso Pointer;

      dcl-s startDate Date(*iso);
      dcl-s endDate Date(*iso);

      pDateIso = %addr(startDate);
      DateIso.day = 1;

      pDateIso = %addr(endDate);
      pDateIso.month = 1;


      You could also leverage RPGIV to create a sub-procedure that does what you want.



      dcl-proc SetDateDay;
      dcl-pi *n Date(*iso);
      date Date const;
      day Int(5) const;
      end-pi

      dcl-ds *n;
      dateIso Date(*iso);
      dateday Signed(2:0) Pos(9);
      end-ds;

      dateIso = date;
      dateday = day;
      return dateIso;
      end-proc;





      share|improve this answer















      There is no function that allows you to edit a portion of a date, time or timestamp field. But as you said, you can do so with a data structure. Given that you don't want to create multiple data structures just for the purpose of setting the day value of multiple date fields, you could use a single Based data structure like this:



      dcl-ds DateIso Qualified Based(%pDateIso);
      year Signed(4:0) Pos(1);
      month Signed(2:0) Pos(6);
      day Signed(2:0) Pos(9);
      end-ds;
      dcl-s pDateIso Pointer;

      dcl-s startDate Date(*iso);
      dcl-s endDate Date(*iso);

      pDateIso = %addr(startDate);
      DateIso.day = 1;

      pDateIso = %addr(endDate);
      pDateIso.month = 1;


      You could also leverage RPGIV to create a sub-procedure that does what you want.



      dcl-proc SetDateDay;
      dcl-pi *n Date(*iso);
      date Date const;
      day Int(5) const;
      end-pi

      dcl-ds *n;
      dateIso Date(*iso);
      dateday Signed(2:0) Pos(9);
      end-ds;

      dateIso = date;
      dateday = day;
      return dateIso;
      end-proc;






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Mar 11 at 17:33

























      answered Mar 7 at 18:36









      jmarkmurphyjmarkmurphy

      7,9362041




      7,9362041







      • 1





        If this is what he's asking for, another alternative is to use embedded SQL to pull the day or year from the date: exec sql set :dateDay = Day(:dateIso)

        – Player1st
        Mar 7 at 20:03













      • 1





        If this is what he's asking for, another alternative is to use embedded SQL to pull the day or year from the date: exec sql set :dateDay = Day(:dateIso)

        – Player1st
        Mar 7 at 20:03








      1




      1





      If this is what he's asking for, another alternative is to use embedded SQL to pull the day or year from the date: exec sql set :dateDay = Day(:dateIso)

      – Player1st
      Mar 7 at 20:03






      If this is what he's asking for, another alternative is to use embedded SQL to pull the day or year from the date: exec sql set :dateDay = Day(:dateIso)

      – Player1st
      Mar 7 at 20:03














      1














      I would definitely create a set of procedures to create a Date, Time, or Timestamp from the various parts. To handle the fact that the year might be in two parts, define the fourth "century" parameter as OPTIONS(*NOPASS), and if that's not passed, the procedure would expect the year part to have all four digits.



      date = makeDate(dd : mm : yy);
      or
      date = makeDate(dd : mm : yy: cc);


      If you don't want to create a few procedures either, there's actually a way to do this without anything extra:



       date = %date(cc * 1000000 + yy * 10000 + mm * 100 + dd); // untested


      But that's some nasty code ...






      share|improve this answer



























        1














        I would definitely create a set of procedures to create a Date, Time, or Timestamp from the various parts. To handle the fact that the year might be in two parts, define the fourth "century" parameter as OPTIONS(*NOPASS), and if that's not passed, the procedure would expect the year part to have all four digits.



        date = makeDate(dd : mm : yy);
        or
        date = makeDate(dd : mm : yy: cc);


        If you don't want to create a few procedures either, there's actually a way to do this without anything extra:



         date = %date(cc * 1000000 + yy * 10000 + mm * 100 + dd); // untested


        But that's some nasty code ...






        share|improve this answer

























          1












          1








          1







          I would definitely create a set of procedures to create a Date, Time, or Timestamp from the various parts. To handle the fact that the year might be in two parts, define the fourth "century" parameter as OPTIONS(*NOPASS), and if that's not passed, the procedure would expect the year part to have all four digits.



          date = makeDate(dd : mm : yy);
          or
          date = makeDate(dd : mm : yy: cc);


          If you don't want to create a few procedures either, there's actually a way to do this without anything extra:



           date = %date(cc * 1000000 + yy * 10000 + mm * 100 + dd); // untested


          But that's some nasty code ...






          share|improve this answer













          I would definitely create a set of procedures to create a Date, Time, or Timestamp from the various parts. To handle the fact that the year might be in two parts, define the fourth "century" parameter as OPTIONS(*NOPASS), and if that's not passed, the procedure would expect the year part to have all four digits.



          date = makeDate(dd : mm : yy);
          or
          date = makeDate(dd : mm : yy: cc);


          If you don't want to create a few procedures either, there's actually a way to do this without anything extra:



           date = %date(cc * 1000000 + yy * 10000 + mm * 100 + dd); // untested


          But that's some nasty code ...







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 7 at 22:15









          Barbara MorrisBarbara Morris

          1,17445




          1,17445





















              0














              Are you asking how you add or substract days, months, years, etc to an RPG date field? I think you may want to peruse the list of RPGLE built-in functions here:
              https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/rzasd/bifs.htm



              If you click on %DAYS for instance, it will lead you to an example here: https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/rzasd/bbmon.htm#bbmon__ebmonths






              share|improve this answer



























                0














                Are you asking how you add or substract days, months, years, etc to an RPG date field? I think you may want to peruse the list of RPGLE built-in functions here:
                https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/rzasd/bifs.htm



                If you click on %DAYS for instance, it will lead you to an example here: https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/rzasd/bbmon.htm#bbmon__ebmonths






                share|improve this answer

























                  0












                  0








                  0







                  Are you asking how you add or substract days, months, years, etc to an RPG date field? I think you may want to peruse the list of RPGLE built-in functions here:
                  https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/rzasd/bifs.htm



                  If you click on %DAYS for instance, it will lead you to an example here: https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/rzasd/bbmon.htm#bbmon__ebmonths






                  share|improve this answer













                  Are you asking how you add or substract days, months, years, etc to an RPG date field? I think you may want to peruse the list of RPGLE built-in functions here:
                  https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/rzasd/bifs.htm



                  If you click on %DAYS for instance, it will lead you to an example here: https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/rzasd/bbmon.htm#bbmon__ebmonths







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 7 at 17:35









                  Player1stPlayer1st

                  1,033713




                  1,033713



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55043879%2fediting-portions-of-date-field-to-compose-a-date-value%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                      Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                      2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived