user4084811
user4084811

Reputation:

In Jaspersoft Studio, how do I use the DATEFORMAT() function?

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.

Upvotes: 1

Views: 22276

Answers (2)

Madsen
Madsen

Reputation: 21

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())

Upvotes: 2

mrabbi
mrabbi

Reputation: 200


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.

Upvotes: 1

Related Questions