0

I want a list of months between a start date and end date from the database. For example the start date is 01.01.2020 and the end date is 31.12.2023. Can I use a while clause to get the months like this: 02.20 03.20 04.20 ... 11.23? I need a function that can change the data/output with the crystal reports filter.

Local DateVar startDate := {startdatum};
Local DateVar endDate := {enddatum};
Local DateVar currentDate := startDate;

// Liste der Monate und Jahre
Local StringVar monthList := "";

While currentDate <= endDate Do (
    // Monat und Jahr des aktuellen Datums extrahieren
    Local NumberVar currentMonth := Month(currentDate);
    Local NumberVar currentYear := Year(currentDate);
    
    // Monat und Jahr zur Liste hinzufügen
    monthList := monthList + currentMonth & "/" & currentYear & ", ";

    If currentMonth = 12 Then
        currentDate := Date(currentYear + 1, 1, 1);
    Else
        currentDate := Date(currentYear, currentMonth + 1, 1);
    
    // Überprüfen, ob das aktuelle Datum nach dem Enddatum liegt
    If currentDate > endDate Then 
        // Aktualisiertes Datum zur Liste hinzufügen
        monthList := monthList + Month(currentDate) & "/" & Year(currentDate);
End If;

// Liste der Monate und Jahre ausgeben
{monthList};

0 Answers0