0

I have a formula that is taking an array which outputs number like this 05/28/14 and need to have it formatted as a date. I am using this code and it is telling me "A Subscript must be between 1 and the size of the array.". I think the problem is with my Month field but am unsure.

stringvar array dates;
numbervar d;  
numbervar m;  
numbervar y;  
dates := split({custinvd.cid-sparedate},",");  
d := val(right(dates[1],2));  
m := tonumber(dates[2]);
y := val(left(dates[3],4));  
cdate(d,m,y);
Jesse
  • 27
  • 7
  • how many values are returned from dates? – Siva May 28 '14 at 14:27
  • I guess it is returning only 1 value... instead of 3 values... use `Ubound` to check number of values in an array – Siva May 28 '14 at 14:41
  • The real question here is what data in `{custinvd.cid-sparedate}` looks like. – Ryan May 28 '14 at 14:54
  • The interesting thing with this set of arrays is that it returns information like so "04/14/2014;?;?;??;?" (I was not in charge of how this field was setup and cannot change it at the moment). From what I gather it will only ever display the first value, which is the date of this job, and the rest will always be question marks. Having since learned this I changed dates := split({custinvd.cid-sparedate},","); to dates := split({custinvd.cid-sparedate},";"); but it still leaves me with my original issue, I almost feel like it would be necessary to do a second split after the first. – Jesse May 28 '14 at 15:12

1 Answers1

0

Assuming that {custinvd.cid-sparedate} is always in the format "04/14/2014;?;?;??;?" then you can convert this to a date by simply stripping away the question marks and semicolon delimiters and using the date() function in CR:

date(split({custinvd.cid-sparedate},";")[1])

or, if you will always have leading zeros, you could even use

date(left({custinvd.cid-sparedate},10))
Ryan
  • 7,212
  • 1
  • 17
  • 30
  • @Siva `cdate()` and `date()` are equivalent functions so it doesn't matter which one is used. – Ryan May 29 '14 at 01:32