Unable to convert a date string to a Date object in BIRT [message #254740] |
Fri, 07 September 2007 11: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 17:40   |
Eclipse User |
|
|
|
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 #723547 is a reply to message #723076] |
Thu, 08 September 2011 14:52  |
Eclipse User |
|
|
|
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.04507 seconds