Crystal Report Date formula to make it the end of the month

我是研究僧i 提交于 2019-12-02 02:01:16

问题


I'm new to CR and need a formula that would give me the end of the month a on a date field. If the Date is 628/2012 or 7/12/2012 I need the formula to to be the end of the month no matter which day of the month the field shows. Of course we know that not every month ends on the 30th or 31th and February sometimes 29th or 30th. So what formula can I use to do this

Example field name {table.end_date}

Any help is greatly appreciated.

Thanks in advance.


回答1:


Create a formula field to calculate the end of the month:

//{@EndOfMonth}
// find the first day of the month, add a month to it, then subtract a day
DateAdd("m", 1, DateTime( Year({table.dateField}), Month({table.dateField}), 1, 0,0,0 )) - 1

Create a second formula that will generate a textual representation:

//{@TextRepresentation}
If Isnull({table.end_date}) Then
  Space(8)
Else
  ToText({@EndOfMonth}, "YYYYMMDD")


来源:https://stackoverflow.com/questions/11837372/crystal-report-date-formula-to-make-it-the-end-of-the-month

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!