How to get start and end date for a specific month and year

前端 未结 3 1272
青春惊慌失措
青春惊慌失措 2021-01-24 06:26

I am creating a report in iReport

The user enters a date eg. 2014-09-14

The report then needs to print 2014-09-01 and 2014-09-30

(\"First day of

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-24 07:13

    If you like to do this inside jasper report a good way to go is using variable

    Example: lets assume the date is arriving as a parameter (if you like naturally it can be a field, you just need to switch how the variable is calculated).

    The incoming date (I use directly the java.util.Calendar as class and set a default value so that I can test in preview)

    
        
    
    

    The variable definition, this is beginning of month, create another variable for end of month using getActualMaximum instead of getActualMinimum

    
        
    
    

    since we are using a parameter its enough to set initialValueExpression if you are using a field you need to set the variableExpression

    Thats it we have our date, format it as you like in the textField

    Example

    
      
      
    
    

    Note: if you are using old version of jasper report (3.1 ecc) you need to set correct class on the different expression 's

提交回复
热议问题