Get startdate and enddate for quarter

0
Hi guys, I have the current date and time and i can tell which quarter of the year. From that quarter, how do you know the start and end dates of the quarter? 
asked
2 answers
6

Hi,

 

First, you have to find the quarter of the year for the current date and time. For that quarter you Should pre-defined the Start date and End date. 

answered
6

Use Java Functions if required, Simply solved

 

import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;

public class StartAndEndOfTheQuater{

     public static void main(String []args){
        LocalDate localDate = LocalDate.now();
LocalDate firstDayOfQuarter = localDate.with(localDate.getMonth().firstMonthOfQuarter())
    .with(TemporalAdjusters.firstDayOfMonth());

 

LocalDate lastDayOfQuarter = firstDayOfQuarter.plusMonths(2)
    .with(TemporalAdjusters.lastDayOfMonth());
    System.out.println (" start: " + firstDayOfQuarter + " stop: " + lastDayOfQuarter );
     }
}

 

In Mendix Java Action, You can do like this

   

public Java_action(IContext context, java.lang.Boolean isFirstDay)

    {

        super(context);

        this.isFirstDay = isFirstDay;

    }

 

    @java.lang.Override

    public java.util.Date executeAction() throws Exception

    {

        // BEGIN USER CODE

        LocalDate localDate = LocalDate.now();

        if(isFirstDay){

        LocalDate firstDayOfQuarter = localDate.with(localDate.getMonth().firstMonthOfQuarter()).with(TemporalAdjusters.firstDayOfMonth());

            return new SimpleDateFormat("yyyy-MM-dd").parse(firstDayOfQuarter.toString());

        } else {

            LocalDate lastDayOfQuarter = firstDayOfQuarter.plusMonths(2).with(TemporalAdjusters.lastDayOfMonth());

            return new SimpleDateFormat("yyyy-MM-dd").parse(firstDayOfQuarter.toString());

        }

        // END USER CODE

    }

answered