cancel
Showing results for 
Search instead for 
Did you mean: 

Generate Month and Date as part of the Report header

Former Member
0 Kudos

I would like to generate the month (Decemeber) and year (2008) as part of the report header for a report that is generated once a month. I plan on subtracting 10 days from today just to give an accurate month and year since the report will always be run after the last day of the month, So on January 1, the report will be for December, 2008. Can anybody help with this. I am new to Crystal.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Great James!! but my year shows up as 2008.00

Former Member
0 Kudos

Use this instead:

//{@displaymonthandyear}

"Month: " + monthname(month(dateadd("m", -1, datadate))) + " / " +

"Year: " + totext(year(datadate), "####")

Former Member
0 Kudos

How does crystal know what MONTH and YEAR is current?

Former Member
0 Kudos

It depends on what built-in function (or field) you are using. In your case, in the formula above, datadate is the built-in crystal function that determines what the current date is. The dateadd("m", -1, datadate) subtracts 1 month from current date.

I hope this answers your question.

Former Member
0 Kudos

Thanks Zach!!

Former Member
0 Kudos

though this Question is answered , i would like to put forward one point

the formula

"Month: " + monthname(month(dateadd("m", -1, datadate))) + " / " +

"Year: " + totext(year(datadate), "####")

would not work in January month as it would return the current year i.e 2009 where as month returned would be December

the proper fomula would be to replace even datadate with dateadd("m", -1, datadate) so the final formula will be

"Month: " + monthname(month(dateadd("m", -1, datadate))) + " / " +

"Year: " + totext(year(dateadd("m", -1, datadate)), "####")

Former Member
0 Kudos

You are correct. Also my original idea was to subtract 10 days from todays date and pull the month and year from that date. This covers me in case the report is run in the same month that the data is for when I run the report. Any help on this? Alos, what does the "m" do in the formula? I thought it had something to do with month but it's used in your example to pull the year?

Edited by: John A Candidi on Dec 19, 2008 8:37 PM

Former Member
0 Kudos

Dear John ,

You can go for subtracting 10 days as well , but again it will have some limitation the report can't be run in the first 10 days of current month and after 11th in next month

if you are opting for 10 days logic, the formula would be

"Month: " + monthname(month(dateadd("d", -10, datadate))) + " / " +

"Year: " + totext(year(dateadd("d", -10, datadate)), "####")

here d represent days , [ m in previous formula does mean month only]

dateadd("d, -10 ,datadate) --> returns date subtracting 10 days from current date

dateadd("m, -1 ,datadate)--> returns date subtarcting 1 month from current date

year(date)--> returns the Year of Date passed to the function

but rather than hardcoding try to use parameter fields.explain ur scenario and lets see how can we make it better

Regard's

AGR

Answers (1)

Answers (1)

Former Member
0 Kudos

Create a formula such as:

//{@displaymonthandyear}

"Month: " + monthname(month(dateadd("m", -1, datadate))) + " / " +

"Year: " + totext(year(datadate))