Cobol Foro

Cobol Foro (https://www.cobolforo.es/index.php)
-   PowerCOBOL (ActiveX, v4 - v11) (https://www.cobolforo.es/forumdisplay.php?f=9)
-   -   [Sintaxis] weekday en ctMonth1 (https://www.cobolforo.es/showthread.php?t=1468)

Breew 19 de abril de 2022 10:41

weekday en ctMonth1
 
Hola amigos.

Tengo el ctMonth1 en una aplicacion y quisiera que me diera el numero de semana en que esta la fecha.
No encuentro como hacerlo.

Alguno me puede ayudar ?

Gracias



.

Joseg 19 de abril de 2022 11:32

Cita:

Citación del post de Breew (Mensaje 7716)
Hola amigos.

Tengo el ctMonth1 en una aplicacion y quisiera que me diera el numero de semana en que esta la fecha.
No encuentro como hacerlo.

Alguno me puede ayudar ?

Gracias


.


Nr. de Semana de qualquer data.



Código COBOL:
  1.  WORKING-STORAGE SECTION.
  2.  01 WORK-DATE.
  3.     02 W-CCYY     PIC 9(4).
  4.     02 W-MONTH    PIC 9(2).
  5.     02 W-DAY      PIC 9(2).
  6.  01 WORK-DATE-PRV-YEAR.
  7.     02 W-CCYY-1   PIC 9(4).
  8.     02 W-MONTH-1  PIC 9(2).
  9.     02 W-DAY-1    PIC 9(2).
  10.  01 WORK-SERIAL   PIC S9(9) BINARY.
  11.  01 START-YEAR    PIC S9(8).
  12.  01 WORK-NUM      PIC 9(8).
  13.  01 DAYS          PIC 9(3) USAGE DISPLAY.
  14.  
  15.  01 NRSEMANA      PIC 99.
  16.  
  17.  PROCEDURE       DIVISION.
  18.         MOVE 20221010 TO WORK-DATE
  19.         SUBTRACT 1 FROM W-CCYY GIVING W-CCYY-1
  20.         MOVE 12 TO W-MONTH-1
  21.         MOVE 31 TO W-DAY-1
  22.         MOVE WORK-DATE TO WORK-NUM
  23.         COMPUTE WORK-SERIAL = FUNCTION INTEGER-OF-DATE(WORK-NUM)
  24.         MOVE WORK-DATE-PRV-YEAR TO WORK-NUM
  25.         COMPUTE START-YEAR = FUNCTION INTEGER-OF-DATE(WORK-NUM)
  26.         COMPUTE DAYS = WORK-SERIAL - START-YEAR
  27.         COMPUTE NRSEMANA = FUNCTION INTEGER((DAYS - 1) / 7) + 1

Breew 19 de abril de 2022 12:42

Cita:

Citación del post de Joseg (Mensaje 7717)
Nr. de Semana de qualquer data.

Código COBOL:
  1.  WORKING-STORAGE SECTION.
  2.  01 WORK-DATE.
  3.     02 W-CCYY     PIC 9(4).
  4.     02 W-MONTH    PIC 9(2).
  5.     02 W-DAY      PIC 9(2).
  6.  01 WORK-DATE-PRV-YEAR.
  7.     02 W-CCYY-1   PIC 9(4).
  8.     02 W-MONTH-1  PIC 9(2).
  9.     02 W-DAY-1    PIC 9(2).
  10.  01 WORK-SERIAL   PIC S9(9) BINARY.
  11.  01 START-YEAR    PIC S9(8).
  12.  01 WORK-NUM      PIC 9(8).
  13.  01 DAYS          PIC 9(3) USAGE DISPLAY.
  14.  
  15.  01 NRSEMANA      PIC 99.
  16.  

Hola.
Perfecto, pero como le corrijo la posicion de la primera semana, ya que ahora no me da semana 2 hasta el dia 8 y queria semana 2 en el dia 3.

Gracias

Joseg 19 de abril de 2022 19:12

Hummmm !

É necessário mais código, teste isto.
Havia muitas considerações a analisar.
No entanto assume que o 1º dia da semana é "Segunda-feira" (Lunes)
Código COBOL:
  1.  data division.
  2.  working-storage section.
  3.  01 input-data pic 9(8) value 20220101.
  4.  01 integer-of-input-data binary pic 9(8).
  5.  01 work-table.
  6.      02 work-item occurs 3.
  7.         03 work-year binary pic 9(4).
  8.         03 work-jan-4 binary pic 9(8).
  9.         03 work-first-date binary pic 9(8).
  10.  01 work-sub binary pic 9(4).
  11.  01 week-for-input-data pic 9(2).
  12.  procedure division.
  13.  inicio.
  14.       perform with test after until input-data = 0
  15.       display "Digite a data YYYYMMDD: " with no advancing
  16.       accept input-data
  17.       if input-data = 0
  18.          exit program
  19.       else
  20.          perform calculos
  21.          display "Nr. da semana da data: " input-data " e "
  22.          week-for-input-data " do ano: " work-year (work-sub)
  23.       end-if
  24.       end-perform
  25.       exit program
  26.       .
  27.  calculos.
  28.       divide input-data by 10000 giving work-year (2)
  29.       subtract 1 from work-year (2) giving work-year (1)
  30.       add 1 to work-year (2) giving work-year (3)
  31.       perform varying work-sub from 1 by 1
  32.          until work-sub > 3
  33.            compute work-jan-4 (work-sub) =
  34.            function integer-of-date(work-year (work-sub) * 10000 + 0104)
  35.            compute work-first-date (work-sub) =(function integer ((work-jan-4 (work-sub) - 1) / 7)) * 7 + 1
  36.        end-perform
  37.        compute integer-of-input-data = function integer-of-date (input-data)
  38.        evaluate integer-of-input-data
  39.           when work-first-date (1) thru (work-first-date (2) - 1)
  40.                move 1 to work-sub
  41.                perform calculate-nr-semana
  42.           when work-first-date (2) thru (work-first-date (3) - 1)
  43.                move 2 to work-sub
  44.                perform calculate-nr-semana
  45.           when other
  46.                move 3 to work-sub
  47.                perform calculate-nr-semana
  48.        end-evaluate
  49.        .
  50.  calculate-nr-semana.
  51.        compute week-for-input-data = (function integer ((integer-of-input-data - work-first-date (work-sub)) / 7)) + 1
  52.        .


La franja horaria es GMT +2. Ahora son las 14:55.

Powered by: vBulletin, Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.