Help with Currentdate
Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=22824
Printed Date: 19 Apr 2024 at 10:13am
Topic: Help with Currentdate
Posted By: Beso90
Subject: Help with Currentdate
Date Posted: 03 Oct 2019 at 6:01am
Hello there,
I have a report that looks at the balances of each GL Account by GL Year and Period.
What I'm struggling with is having the report look at current year and current period.. Currently it has a parameter where I enter the year and the period.. I want it to automatically look at current year and current period.
Table name is V_GLYEAR_PERIODS
The fields that I think could help are:
FISCALYR_START (date/time) <-- this one is ALWAYS January first of each year: 2019/01/01 00:00:00.00
FISCALYR_END (date/time) <-- this one is ALWAYS December 31st of each year: 2019/12/31 00:00:00.00
Now the Periods:
I have 3 fields, PERIOD, PERIOD_START_DATE, and PERIOD_END_DATE
I believe the field PERIOD is the easiest, since it ALWAYS has values from 1-12 (each number represents the month of the year).
Can someone please help me write the selection formula so I can get rid of the parameter and have the report automatically pull current year/period?
Thank you and best regards,
Bas
|
Replies:
Posted By: DBlank
Date Posted: 03 Oct 2019 at 8:55am
Something like this...?
year(currentdate)=year({Clients.FISCALYR_START})
and month(currentdate)=PERIOD
|
Posted By: Beso90
Date Posted: 03 Oct 2019 at 9:29am
It keeps telling me "Bad Date Format string"
because the value that's in FISCALYR_START is 2019/01/01 00:00:00.00
so I tried to put it in a formula that would convert it to a date field, and it still doesn't work
I tried these:
DateValue({V_GLYEAR_PERIODS.FISCALYR_START})
cDate(ToText(cDate({V_GLYEAR_PERIODS.FISCALYR_START}),"yyyyMMdd"))
and they both still give me a "Bad date format string"
how can i convert this 2019/01/01 00:00:00.00 string to a date?
|
Posted By: DBlank
Date Posted: 03 Oct 2019 at 9:47am
if that is always the format grab the left 4 characters and convert to an int
year(currentdate)=tonumber(left({field},4))
|
Posted By: Beso90
Date Posted: 03 Oct 2019 at 9:56am
Here is what I did and worked:
Created a formula called it {@FiscalStart} and it contains:
stringvar MyDateStr:= {V_GLACCT_YBB_ALL_PERIODS_CUMM.GLYEAR_START_DATE};
datetimevar MyDate;
MyDate:= cdatetime(val(mid(MyDateStr,1,4)),val(mid(MyDateStr,6,2)),val(mid(MyDateStr,9,2))
,val(mid(MyDateStr,12,2)),val(mid(MyDateStr,15,2)),val(mid(MyDateStr,18,2)));
MyDate
then created formula called it {@FiscalStart2} and it contains:
date({@FiscalStart})
Then in the selection formula, I used the formula you provided previously:
(year(currentdate)=year({@FiscalStart 2})
and month(currentdate)={V_GLYEAR_PERIODS.PERIOD})
Thank you so much!!!
|
|