Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Unable to convert a date string to a Date object in BIRT
Unable to convert a date string to a Date object in BIRT [message #254740] Fri, 07 September 2007 15:23 Go to next message
Eclipse UserFriend
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 Go to previous messageGo to next message
Alex Krücken is currently offline Alex KrückenFriend
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 #718994 is a reply to message #254740] Thu, 25 August 2011 18:08 Go to previous messageGo to next message
kayanserdar is currently offline kayanserdarFriend
Messages: 20
Registered: April 2011
Junior Member
Hi there , i have a similar issue in XML source file.
My dates in XMl source file looks like below:
Month:
Month:

June -2004
July-2004
...

I have added a comuputed column named "Date" with below expression:
df = new Packages.java.text.SimpleDateFormat("yyyy-MM-dd");
myDate = df.parse(row["Month"]);
myDate;

However i always get below error:
Fail to compute value for computed column "Date".
A BIRT exception occurred: There are errors evaluating script "df = new Packages.java.text.SimpleDateFormat("yyyy-MM-dd");

myDate = df.parse(row["Month"]);

If you have noticed, I am getting two "Months" highlighted in red above in my XML source and not sure if this is causing an error. If so, not sure how to removed.

Please assist in your earliest convenience.
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 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

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 #719022 is a reply to message #719008] Thu, 25 August 2011 20:15 Go to previous messageGo to next message
kayanserdar is currently offline kayanserdarFriend
Messages: 20
Registered: April 2011
Junior Member
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 #719031 is a reply to message #719022] Thu, 25 August 2011 20:40 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

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 #719046 is a reply to message #719031] Thu, 25 August 2011 22:02 Go to previous messageGo to next message
kayanserdar is currently offline kayanserdarFriend
Messages: 20
Registered: April 2011
Junior Member
sure, please find enclosed zip file.

Cheers,
Serdar
Re: Unable to convert a date string to a Date object in BIRT [message #720488 is a reply to message #719031] Tue, 30 August 2011 17:21 Go to previous messageGo to next message
kayanserdar is currently offline kayanserdarFriend
Messages: 20
Registered: April 2011
Junior Member
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 #720563 is a reply to message #720488] Tue, 30 August 2011 20:08 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

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 #723076 is a reply to message #720563] Wed, 07 September 2011 15:00 Go to previous messageGo to next message
kayanserdar is currently offline kayanserdarFriend
Messages: 20
Registered: April 2011
Junior Member
Hello Jason,
Sorry for getting back to you. This solution works great Smile
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"]);
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 Go to previous message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

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"]);
Previous Topic:[Resolved] JAR file calling Birt, problems Upgrading to 3.7
Next Topic:Dataset joins uses long names as alias
Goto Forum:
  


Current Time: Wed Apr 24 17:15:39 GMT 2024

Powered by FUDForum. Page generated in 0.04176 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top