By: Jordon - jordonj
Is there a way to change a double to a date?
2004-09-13 12:47
I have a paremter and a field in a table that are declared as double, but they are really dates. Is there a way to convert the double to a date, for print formatting?
By: Ralf Weinand - weinanr
RE: Is there a way to change a double to a da
2004-09-20 07:25
Hi Jordan,
try to convert the double into long
and use the constructor
new Date(long)
to create the Date object.
Regards,
Ralf
By: Andrew McLaughlin - pik0
RE: Is there a way to change a double to a da
2004-09-20 09:19
Why are you converting a double to Date? Perhaps the Field reference should be update? What format is the date being stored?
Piko
By: Jordon - jordonj
RE: Is there a way to change a double to a date?
2004-09-23 06:09
the date is stored as a double, so I wanted to convert it to date for displaying properly; I used toString and concatenated to get what I wanted, but I was just wondering if there was an easier way...
By: Andrew McLaughlin - pik0
RE: Is there a way to change a double to a date?
2004-09-23 09:34
Right on. Well here's how:
new Date( ( long ) $F{ Date_Column }.doubleValue() )
Piko
By: Jordon - jordonj
RE: Is there a way to change a double to a date?
2004-09-28 05:44
well, that gave me a date, but not the correct date....
20040907 came out as Wed Dec 31 23
By: Andrew McLaughlin - pik0
RE: Is there a way to change a double to a date?
2004-09-28 11:31
Ah...
I assumed that since the date was a double that it was a serial value. Now I realize that it's just a ymd encoded string. Here's how to convert it:
new SimpleDateFormat( "yyyyMMdd" ).parse( "" + $F{ double_date_field } )
That should properly convert the data. Note the "" + in the parse function call is to convert the double to a String.
While I'm on it, why do you have the date column defined as a double? Since it's really just year month day, it will work easier if you change it to the String that it is... :)
Piko
By: Jordon - jordonj
RE: Is there a way to change a double to a date?
2004-09-29 09:52
that didn't work either.....
java.text.ParseException: Unparseable date: "2.0040907E7"
I didn't define the field that way... It's coming from a table defined in our software...
By: Andrew McLaughlin - pik0
RE: Is there a way to change a double to a date?
2004-09-29 11:19
Okay, change the field type definition from double to String. Then it will work... :)
Piko
By: Jordon - jordonj
RE: Is there a way to change a double to a date?
2004-09-29 11:57
nope.....
found : java.util.Date
required: java.lang.String
value = (java.lang.String)(new SimpleDateFormat("yyyyMMdd").parse("" + ((java.land.Double)field_EGACDT.getValue())));
any other ideas?
By: Andrew McLaughlin - pik0
RE: Is there a way to change a double to a date?
2004-09-29 12:54
You have to change the data type for field_EGACDT to String instead of Double. That's the problem.
Piko
Is there a way to change a double to a date?
2004-09-13 12:47
I have a paremter and a field in a table that are declared as double, but they are really dates. Is there a way to convert the double to a date, for print formatting?
By: Ralf Weinand - weinanr
RE: Is there a way to change a double to a da
2004-09-20 07:25
Hi Jordan,
try to convert the double into long
and use the constructor
new Date(long)
to create the Date object.
Regards,
Ralf
By: Andrew McLaughlin - pik0
RE: Is there a way to change a double to a da
2004-09-20 09:19
Why are you converting a double to Date? Perhaps the Field reference should be update? What format is the date being stored?
Piko
By: Jordon - jordonj
RE: Is there a way to change a double to a date?
2004-09-23 06:09
the date is stored as a double, so I wanted to convert it to date for displaying properly; I used toString and concatenated to get what I wanted, but I was just wondering if there was an easier way...
By: Andrew McLaughlin - pik0
RE: Is there a way to change a double to a date?
2004-09-23 09:34
Right on. Well here's how:
new Date( ( long ) $F{ Date_Column }.doubleValue() )
Piko
By: Jordon - jordonj
RE: Is there a way to change a double to a date?
2004-09-28 05:44
well, that gave me a date, but not the correct date....
20040907 came out as Wed Dec 31 23
By: Andrew McLaughlin - pik0
RE: Is there a way to change a double to a date?
2004-09-28 11:31
Ah...
I assumed that since the date was a double that it was a serial value. Now I realize that it's just a ymd encoded string. Here's how to convert it:
new SimpleDateFormat( "yyyyMMdd" ).parse( "" + $F{ double_date_field } )
That should properly convert the data. Note the "" + in the parse function call is to convert the double to a String.
While I'm on it, why do you have the date column defined as a double? Since it's really just year month day, it will work easier if you change it to the String that it is... :)
Piko
By: Jordon - jordonj
RE: Is there a way to change a double to a date?
2004-09-29 09:52
that didn't work either.....
java.text.ParseException: Unparseable date: "2.0040907E7"
I didn't define the field that way... It's coming from a table defined in our software...
By: Andrew McLaughlin - pik0
RE: Is there a way to change a double to a date?
2004-09-29 11:19
Okay, change the field type definition from double to String. Then it will work... :)
Piko
By: Jordon - jordonj
RE: Is there a way to change a double to a date?
2004-09-29 11:57
nope.....
found : java.util.Date
required: java.lang.String
value = (java.lang.String)(new SimpleDateFormat("yyyyMMdd").parse("" + ((java.land.Double)field_EGACDT.getValue())));
any other ideas?
By: Andrew McLaughlin - pik0
RE: Is there a way to change a double to a date?
2004-09-29 12:54
You have to change the data type for field_EGACDT to String instead of Double. That's the problem.
Piko
0 Answers:
No answers yet