You need to sign in to do that
Don't have an account?
daysbetween bug?
I have the following code --
Date ad = this.event.Start_Date_vod__c;
Date bd = this.event.End_Date_vod__c;
Integer di = ad.daysBetween(bd);
cm.avai0 = ad+' booyaaa '+bd;
Edited to add -- both Start_Date_vod__c and End_Date_vod__c are declared as datatype Date in the SObject.
that throws the error --
java.lang.String cannot be cast to java.util.Date
When I comment out this line --
Integer di = ad.daysBetween(bd);
The error goes away and the code continues to run. I'm not sure what I'm doing wrong. I'm comparing the days between two date objects. I tried using comparison operators such as > and < but that throws the String cannot be cast as Date error as well.
Any help is appreciated.
Are you using APEX? Or JAVA?
In APEX, I tried your code on 2 of my own date fields. Verify that you are truly dealing with a date-data-type. To verify strange issues like this, I use Force.com's IDE version of 'Execute Anonymous' in eclipse to test this stuff. Notice how I put system.debug statements to see the actual values.
SomeCustomObject__c cd = [Select name, Start_Date_vod__c, End_Date_vod__c From SomeCustomObject__c where id = '??????']; Date ad = cd.Start_Date_vod__c; System.debug('ad = ' + ad); Date bd = cd.End_Date_vod__c; System.debug('bd = ' + bd); Integer di = ad.daysBetween(bd); System.debug('di = ' + di); String str = 'Date1: ' + ad + ' Date2: ' + bd + ' DaysBetween:' + di; System.debug(str);
Here's the result I received with my 2 date fields. My dates are showing in the expected format for my locale (YYYY-MM-DD HH:MM:DD).
Anonymous execution was successful. 20090512190405.008:AnonymousBlock: line 1, column 24: SOQL query with 1 row finished in 7 ms 20090512190405.008:AnonymousBlock: line 3, column 1: ad = 2008-01-01 00:00:00 20090512190405.008:AnonymousBlock: line 5, column 1: bd = 2009-12-31 00:00:00 20090512190405.008:AnonymousBlock: line 7, column 1: di = 730 20090512190405.008:AnonymousBlock: line 9, column 1: Date1: 2008-01-01 00:00:00 Date2: 2009-12-31 00:00:00 DaysBetween:730
You must test for null explicitly ,
if ( myobj.myfield__c != null ) { // can compare }
I am tring the following code
values.add(new Pack__TCI__c(Pack__Report_Type__c=report ,Pack__Opp_Index__c = 7.53,Pack__Con__c = 13.2,Zymepack__Date_of_Entry__c = tCIUser.Pack__Start_Date__c));
insert values;
and I was facing the error
java.lang.String cannot be cast to java.util.Date
now just for testing I have done
Pack__TCI__c values= new Pack__TCI__c(Pack__Opp_Index__c = 7.65,Pack__Con__c = 7.83);
insert values;
yet I am having the same error
java.lang.String cannot be cast to java.util.Date
This is really strange and I am not been able to grasp where the error originates!!!