Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
DateFormat in Dynamic Text
vash
Hi,
I have a function to format date as per the different locales.
I want to apply that function to the "Date row" in a dyamic text.
I am attaching a sample report design, with a grid - having a dynamic text and Date element.
I want the same effect of the Date element in the dynamic text.
Please suggest a solution.
Thanks,
Vash
Find more posts tagged with
Comments
mwilliams
Vash,
In you example, you can make the date look the same in the dynamic text box as the other box by putting the line 'def = new SimpleDateFormat("M/d/yy").format(abc);' after the line 'abc = new SimpleDateFormat....' and comment out the last 2 lines. You could also do something like <VALUE-OF format="MMMM d, yyyy h:mm: ss">YOURDATEFIELD</VALUE-OF> in a regular text box.
Hope this helps.
vash
Michael,
I have a dateformat function "YBDateSetup", I need to use that function to format my date. As our templates are used in different regions around the world, I don't want to format it in US format all the time.
That's the reason I have defined my own function.
How do I integrate that function in the dynamic text?
Thanks,
Vash
mwilliams
Vash,
I would think you'd be able to use your function just as you have it set up in your dynamic text box. It seems that the problem that the report is having is with your use of getStyle() in your function, not the use of the function in the dynamic text box.
Of course there isn't an issue with the getStyle() call when the function is used on the data element. I'll have to take a closer look. I'll let you know what I figure out.
vash
Michael,
Yes, the whole problem is - me getting error with getStyle().
So I thought, it wasnt the right way to do it.
Please let me know, when you find a solution.
Thanks,
Vash
mwilliams
Vash,
BIRT has the ablility to pass a locale which automatically changes the format of dates and numbers. You can test this by going to Window -> Preferences -> Report Design -> Preview and change the locale there. You should see the date formats change automatically. Or is there a reason you're trying to do this through a dynamic text element?
vash
Hey Michael,
I get my dates in the format "yyyyMMdd".
I need to format dates with "/" and depending on the locale.
So, for example:
US format: MM/dd/yyyy
UK format: dd/MM/yyyy
And I am using dynamic text, because these dates will be a part of the header or footer with some other "plain text" which is also localized as per the region.
And I want to keep this as one element, so I don't have to worry about centering each element individually, as the plain text will have varying width depending on the language.
Can you suggest some other solution for achieving this?
Thanks,
Vash
Virgil Dodson
Hi Vash,
The TEXT control also allows for Dynamic Text. Take a look at the enclosed example. I modified your example to first create a computed column that turns your String date into a real date... and then used that real date in a TEXT control along with other dynamic text. When I switch the BIRT Viewer locale from English (United States), the date reads MM/DD/YYYY and switching the viewer to English (United Kingdom), the date automatically switches to DD/MM/YYYY. (see screenshot - my additions are bolded)
vash
Virgil,
Your solution works for the already defined formats in Birt.
Short Date has the format M/d/yy, but I want the format MM/dd/yyyy.
That is why I have defined my own format "YBShortDate" and have defined my own format function "YBDateSetup".
YBShortDate is defined in my properties file of all locales.
YBDateSetup formats the date by extracting the format from the properties file.
Is it possible to format the date using my function "YBDateSetup" (already present in the Script tab of my report design) in dynamic text or text element????
Thanks,
Vaishali
Virgil Dodson
Hi Vaishali,<br />
<br />
Your fuction does something very specific to a Data Control using the getStyle() method that is not available in a Dynamic Text Control. If your function took the date, formatted it however it wanted, and then returned a string date then it would work.<br />
<br />
You can continue to format individual Data Controls like you are doing today, and then just use the INLINE property to make sure other static elements appeared directly after one another. An example is located at <a class='bbc_url' href='
http://www.birt-exchange.org/forum/designing-birt-reports/15807-how-set-localization-text-dynamically.html#post51840'>http://www.birt-exchange.org/forum/designing-birt-reports/15807-how-set-localization-text-dynamically.html#post51840</a>
;
vash
Virgil,
So, for example if I have a text element "text" and a date element "date".
Text element is some static text which will be localized.
Date element is formatted according to my function "YBDateSetup".
Now I want to display both elements one after another, how can I do it using INLINE property?
Thanks,
Vash