Home
Analytics
Formatting Date Time in local time
Paul A
Hi again,
I have 2 report parameters that are of Date Time type. These are DateFrom, DateTo.
When I click on preview I am prompted to enter the date and time. For these I enter the following:
DateFrom: 2011-07-10 00:00:00
DateTo: 2011-07-10 23:45:00
When I receive these in my ODA Driver, they are converted to GMT fine. NOTE I am running this under my timezone of UTC Dublin, Edinburgh, Lisbon, London on Windows 7 with Day Light Saving checked.
When I run the report they get passed into my driver query as:
DateFrom: 2011-07-09 23:00:00
DateTo: 2011-07-10 22:45:00
This is correct. I do my lookups etc no problem.
The issue I have is displaying the report parameters on the actual report. I have dragged the DateFrom and DateTo onto it. When the report is run, the date time is displayed as:
DateFrom: 2011-07-09 23:00:00
DateTo: 2011-07-10 22:45:00
I would like this to be in local time as what was initially input:
DateFrom: 2011-07-10 00:00:00
DateTo: 2011-07-10 23:45:00
I thought I came across a setting for using date time as universal or local somewhere but I cannot remember where. I have tried doing this in script to no avail.
params["DateFrom"].value.toLocaleString() ???? does not display anything...
Any help greatly appreciated.
Andez
Find more posts tagged with
Comments
mwilliams
So, when you say converted to GMT, you're actually replacing the value of the parameter with the new value?
Paul A
Hi Mike,<br />
<br />
The issue is I enter the DateFrom report parameter as 2011-07-10 00:00:00 when the prompt appears when I preview the report. This to me is in local time.<br />
<br />
When the preview appears, the report parameter on my report is 2011-07-09 23:00:00. This to me in Universal Time (UTC).<br />
<br />
I am not changing any report parameter values, I am just trying to get the report to display what I entered into the DateFrom parameter what I would expect which is 2011-07-10 00:00:00 BST as we are in British Summer time.<br />
<br />
This would appear to be a formatting issue.<br />
<br />
If I change the format on the DateFrom in the Format DateTime properties to:<br />
Format: Custom<br />
Locale: English (United Kingdom)<br />
Format Code: d MMMM y HH:mm:ss z<br />
<br />
Then I get the date formatted as 2011-07-09 23:00:00 GMT. This is essentially correct, but I would want it to be displayed as 2011-07-10 00:00:00 BST as we are in summertime.<br />
<br />
As additional information, when I debug the ODA driver the report parameter DateFrom is passed to it as a Timestamp (through the various BIRT layers) and has the value 2011-07-09 23:00:00. When working with any date time in java, it is always stored in Universal Time from my understanding. Therefore when I enter the value of 2011-07-10 00:00:00 into the DateFrom parameter in the report prompt it must assume this is local date time taking into account my system settings which is currently in British Summertime which is one hour difference from UTC. <br />
<br />
My date time column where I build up a ResultSet is all stored in Universal Time. When it comes to display the data I want to format this in local time but I have the same issue as the formatting the DateFrom report parmeter.<br />
<br />
Hope this helps :-S<br />
<br />
Andez<br />
<br />
<br />
<br />
<br />
<br />
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="80734" data-time="1311864953" data-date="28 July 2011 - 07:55 AM"><p>
So, when you say converted to GMT, you're actually replacing the value of the parameter with the new value?<br /></p></blockquote>
mwilliams
One simple thing you could do would be to write a short script that uses the BIRT function, BirtDateTime.addHour(dateTimeField,numHours), to add the extra hour back on.
cypherdj
Birt expressions actually support java, so what you could do is import SimpleDateFormat and apply the exact formatting you want:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.java.util.Locale);
importPackage(Packages.java.lang.SimpleDateFormat);
myFormat = "yyyy-MM-dd h24:mi:ss z";
Locale locale = Locale.UK;
SimpleDateFormat format = new SimpleDateFormat(myFormat, locale);
format.parse(param["DateFrom"].value);
</pre>
<br />
Or simply (this should use the default locale, which should be UK in your case):<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
importPackage(Packages.java.lang.DateFormat);
DateFormat.getInstance().parse(param["DateFrom"].value);
</pre>
Paul A
A little bit more information on the problem.<br />
<br />
This is only evident when I am debugging my ODA Driver in my Eclipse Indigo SDK. Withing Eclipse SDK debugging session:<br />
<br />
I enter my parameter as 22 July 2011 00:00:00 and it is displayed as:<br />
22 July 2011 23:00:00<br />
<br />
When I deploy my Driver to either BIRT RCP or BIRT Viewer, it displays fine:<br />
<br />
22 July 2011 00:00:00 GMT+01:00<br />
<br />
This might be an issue with another Date Time issue I came across <a class='bbc_url' href='
http://www.birt-exchange.org/org/forum/index.php/topic/22978-potential-bug-with-date-time-report-parameters/page__fromsearch__1'>Date
Time Bug</a>.<br />
<br />
Andez