Crystal
Reports Training by Ken Hamady, MS, Reporting and Training Nationwide
Free
Crystal Reports formula examples from
KenHamady.com
To
learn
the techniques used in these formulas get:
Character Date to
True Date:
This is a
formula for converting Dates stored as character values into
true date values.
This also solves
the problem of date parameters in Versions 5 and 6
that have to be entered using the function format. With the
following
formula users could enter a date parameter in natural format with
slashes,
and convert it into a true date.
This formula can
adjust for days that are entered with 1 or 2 digits;
months that are entered with 1 or 2 digits; and years that are entered
with 2 or 4 digits. It assumes that your field/parameter entry
will
be a character string that looks like a typical date with slash
separators
such as 12/31/1997. If you have a 4-digit year (recommended) the
formula places it in the specified century. If you have a 2-digit
year it will assume that you are in 19xx if the year is greater than 50
and 20xx if the year is less than 50. This window year can
be changed in line 7.
WhileReadingRecords;
StringVar TextString := {table.TextDate}; // place your field or
parameter
prompt in place of this field
NumberVar
Slash1 := instr(TextString,"/");
NumberVar Slash2 := instr(4,TextString,"/");
NumberVar
Yr := If Length (TextString) - Slash2 > 3
then Val (right(TextString,4))
else if Val (right(TextString,2)) < 50
then Val (right(TextString,2))+2000
else Val (right(TextString,2))+1900;
NumberVar
Mth := Val (Left (TextString,Slash1-1));
NumberVar
Dy := Val (TextString [Slash1+1 to Slash2-1]);
Date(Yr,
Mth, Dy)