Unable to convert a date string to a Date object in BIRT [message #254740] |
Fri, 07 September 2007 15:23 |
Eclipse User |
|
|
|
Originally posted by: jason.estep.cgifederal.com
I have a situation where I need to convert a date in string format to a Date
object, so I can select the MAX (most recent) date time value.
I haven't had any success in converting strings to dates in BIRT. At present
I split the string into its component pieces as separate variables (month,
day, year, hours, minutes, seconds). I have tried reconstructing the string
in various configurations for use with new Date(Date.parse(newDateString))
but Date.parse(newDateString) always returns NaN. I also tried var myDate =
new Date(), and then myDate.setFullYear(year), myDate.setDay(day), etc. This
caused BIRT core exceptions to occur.
Is there a specific string format I have to use for Date.parse? Is there any
other way I can turn this string into a Date object, with the time included?
Thanks,
Jason C. Estep
|
|
|
Re: Unable to convert a date string to a Date object in BIRT [message #254761 is a reply to message #254740] |
Fri, 07 September 2007 21:40 |
Alex Krücken Messages: 8 Registered: July 2009 |
Junior Member |
|
|
Jason,
try Java's SimpleDateFormat:
myString = '15.9.2007 22:30';
df = new Packages.java.text.SimpleDateFormat("dd.M.yyyy HH:mm");
myDate = df.parse(myString);
myTest = DateTimeSpan.addDate(myDate, 0, 0, 1)
You can see or download this example at:
http://e-prostor.com/birt/samples/StringToDate.rptdesign
Alex
Jason Estep pravi:
> I have a situation where I need to convert a date in string format to a Date
> object, so I can select the MAX (most recent) date time value.
>
> I haven't had any success in converting strings to dates in BIRT. At present
> I split the string into its component pieces as separate variables (month,
> day, year, hours, minutes, seconds). I have tried reconstructing the string
> in various configurations for use with new Date(Date.parse(newDateString))
> but Date.parse(newDateString) always returns NaN. I also tried var myDate =
> new Date(), and then myDate.setFullYear(year), myDate.setDay(day), etc. This
> caused BIRT core exceptions to occur.
>
> Is there a specific string format I have to use for Date.parse? Is there any
> other way I can turn this string into a Date object, with the time included?
>
> Thanks,
>
> Jason C. Estep
>
>
|
|
|
|
Re: Unable to convert a date string to a Date object in BIRT [message #719008 is a reply to message #718994] |
Thu, 25 August 2011 19:03 |
|
Do you have a space after month? If not you should be able to create a
column like:
importPackage(Packages.java.text);
new Date(dataSetRow["strdate"])
df = new Packages.java.text.SimpleDateFormat("MMM-yyyy");
myDate = df.parse(dataSetRow["strdate"]);
Then when the date is used in a table just use another date format.
See attached example.
Jason
On 8/25/2011 2:08 PM, kayanserdar wrote:
> df = new Packages.java.text.SimpleDateFormat("yyyy-MM-dd");
> myDate = df.parse(row["Month"]);
-
Attachment: sdsdate.zip
(Size: 1.40KB, Downloaded 457 times)
|
|
|
|
Re: Unable to convert a date string to a Date object in BIRT [message #719031 is a reply to message #719022] |
Thu, 25 August 2011 20:40 |
|
Can you zip the two and repost?
Jason
On 8/25/2011 4:15 PM, kayanserdar wrote:
> Hello Jason,
>
> Thanks you for your prompt response.
>
> I don't have a space in "Month"
> What I am thinking is that i see two headings instead of one and when i try to convert date field, it is trying to extract number from that columns hence error appears.
>
> I have played XPAth to remove one of the headings but so for was unsuccessful.
>
> I am sending XML source and report so it might give you more clear information.
>
> Thanks in advance.
> Serdar
>
>
|
|
|
|
|
Re: Unable to convert a date string to a Date object in BIRT [message #720563 is a reply to message #720488] |
Tue, 30 August 2011 20:08 |
|
Sorry, somehow I missed your response. In this example you first need
to filter out the header and footer from your rows. Look at the filter
on the dataset. Next you need to add the date field to the table
bindings. Look at the expression in the last column of the table.
Jason
On 8/30/2011 1:21 PM, kayanserdar wrote:
> Hello Jason, please let me know if you are/were able to open files that
> I have sent.
>
> Regards,
> Serdar
|
|
|
|
Re: Unable to convert a date string to a Date object in BIRT [message #723547 is a reply to message #723076] |
Thu, 08 September 2011 18:52 |
|
This is because your first and last rows are not formatted as MMM-yyyy.
Jason
On 9/7/2011 11:00 AM, kayanserdar wrote:
> Hello Jason, Sorry for getting back to you. This solution works great :)
> Your help is much appreciated.
>
> Just want to inform you that when I added below expression in a computed
> columns I get same error stated in my previous email, however when i
> added as a column binding works fine.
>
>
>
> importPackage(Packages.java.text);
> new Date(dataSetRow["strdate"])
>
> df = new Packages.java.text.SimpleDateFormat("MMM-yyyy");
> myDate = df.parse(dataSetRow["strdate"]);
|
|
|
Powered by
FUDForum. Page generated in 0.04230 seconds