1

Here's a screenshot:

Here's a screenshot http://www.coletrumbo.com/wp-content/uploads/2015/05/dateformat-1024x575.png

I'm trying to turn the current date into July 1st of the current year using DATEFORMAT(). I learned how to do that in MySQL from this question, and I hoped it would work similarly in Jaspersoft Studio- turns out date_format( curdate(), '%Y-07-01' ) doesn't translate into

DATEFORMAT( TODAY(), '%Y-07-01' ) or DATEFORMAT( TODAY(), YY/07/01 ). Neither worked.

I could keep trying to get creative and hopefully find something that works, but I'd rather actually understand how to use DATEFORMAT().

I checked the Jaspersoft Studio User Guide, but it's not there. From the prompts on the screen, it makes a lot of sense, but I just can't figure out the "format pattern" that I'm allowed to apply, or even how to correctly write any format pattern at all. Also, this conveniently named question, DateFormat Pattern, didn't actually help at all. And community.jaspersoft.com/answers is kind of a joke in my opinion. When I checked it a couple days ago, it was filled with spam linking to live hockey games.

Thanks in advance. I'm sure this is a beginner level question, so I feel dumb asking it, and I feel like I'm wasting other people's space and time with it because I should already know. So I really appreciate your willingness to care.

Community
  • 1
  • 1

2 Answers2

2

I am using the following to get the todays date in a danish format

"Dato: "+new java.text.SimpleDateFormat("dd MMMM yyyy",new Locale("da", "DK")).format(new Date())

Madsen
  • 21
  • 4
1


you can find the source code for the DateTime functions directly in JR repository: https://sourceforge.net/p/jasperreports/code/ci/master/tree/jasperreports/demo/samples/functions/src/net/sf/jasperreports/functions/standard/DateTimeFunctions.java

As you can see the code is fairly simple and relies on the Joda Time library. Therefore the second parameter you are trying to enter is a String, while the first one is a Date object.

Indeed something that could work for you is an expression like this DATEFORMAT(TODAY(), "07-01-YYYY")

Regards,
Massimo.

mrabbi
  • 190
  • 5
  • I'm using Jaspersoft Studio 6.2.0.final.
    If I use the above expression `DATEFORMAT(TODAY(), "07-01-YYYY")` I get the following error:
    Error while processing request:
    net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
    1. The method TODAY() is undefined for the type report_1456696467009_468184
                    value = DATEFORMAT(TODAY(), "07-01-YYYY"); //$JR_EXPR_ID=13$
    
    With Studio 6.2.0 I can get the current date and format it with: `new SimpleDateFormat("dd.MM.yyyy.HH.mm").format(new Date())`
    – jgrocha Feb 28 '16 at 22:05
  • @jgrocha Standard functions like DATEFORMAT were moved outside of jasper core package to `jasperreports-functions`. In order to make it work add this artifact to pom.xml: `net.sf.jasperreports jasperreports-functions` – Michał Stochmal Sep 23 '20 at 14:13