Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Convert Month/Day to useable Format Post Reply Post New Topic
Author Message
JFinzel
Groupie
Groupie
Avatar

Joined: 20 Jul 2011
Location: United States
Online Status: Offline
Posts: 49
Quote JFinzel Replybullet Topic: Convert Month/Day to useable Format
     Posted: 06 Jan 2012 at 5:56am
I have data for a seasonal address that tells me "Seasonal Date From" as "1/1" and "Seasonal Date To" as "4/1" for the data, meaning January 1st and April 1st (no specified year).  As far as I can see, CR does not recognize this as a date.

I need CR to know this is January 1st (so I need to convert it somehow to a readable format), and then I want to show seasonal address within the date range.

I do not know how I would do the formula, but this is what I would want for the SUPPRESSION formula for those who have a seasonal address OUT OF RANGE:

CurrentDate is not between ({CnAdrAll_1.CnAdrAll_1_Seasonal_From},{CnAdrAll_1.CnAdrAll_1_Seasonal_To})

Does this make sense?  Any help is much appreciated.
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 06 Jan 2012 at 6:04am
date(2011,tonumber(left("4/1",instr("4/1","/")-1)),tonumber(right("4/1",len("4/1")-instr("4/1","/"))))
 
replace all the "4/1" with your date fields to convert them to and actual datetime field.
 
EDIT: treats year as 2011.


Edited by rkrowland - 06 Jan 2012 at 6:05am
IP IP Logged
JFinzel
Groupie
Groupie
Avatar

Joined: 20 Jul 2011
Location: United States
Online Status: Offline
Posts: 49
Quote JFinzel Replybullet Posted: 06 Jan 2012 at 7:34am
Thanks for the reply.  This worked perfectly to get my date.

I am trying to understand the formula, and what you did, with my limited knowledge.  I am a bit lost but am glad it works.

I figured out how to suppress using:

CurrentDate in DateTime ({SeasonalFrom}) to DateTime ({SeasonalTo})

As far as I can see, this worked like a charm.

One problem though, the following returns an error:

Not (CurrentDate in DateTime ({SeasonalFrom}) to DateTime ({SeasonalTo}))

I want to use the above formula when the date is outside of range.  Any help with this one?

Thank you!
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 10 Jan 2012 at 1:23am

Hi, a brief explanation of how it works -

Date() - Will convert 3 numbers to a date (YYYY,MM,DD)
 
to get the MM we used tonumber(left("4/1",instr("4/1","/")-1))
 
The tonumber converts the text string into a number which is useable within the Date funtion.
 
The month in your string is everything before the "/" so we do a left to trim the field to the number of characters required.
 
The Instr calculates the number of characters we need in our left by searching the string for "/" - ie instr("4/1","/") would return 2 as the "/" is the 2nd character - we do the -1 as we need everything before the "/".
 
We do the same for the DD using right and len instead of left.
 
Try these formulas instead;
 
Inside Range
currentdate >= {seasonalfrom} and currentdate <= {seasonalto}
 
Outside Range
currentdate < {seasonalfrom} or currentdate > {seasonalto}
 
Regards,
Ryan.


Edited by rkrowland - 10 Jan 2012 at 1:25am
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum