Extracting Only Year Value in Crystal Report DateTime Field

只愿长相守 提交于 2021-02-04 13:46:11

问题


I am working with Crystal Report, right now I am in a situtation where I have to extract only Year value from a datetiem field, for example, if the value is : 01/03/2014 10:20:01AM

I only need to extract 2014

I did what is that , I changed the DataFormat of the field is dd/mm/yyyyy

Now i hav eapplied formula on it.

Formula = Right(CStr ({report;1.FirstYearDate}),4)

It shows 01AM

Kindly help me out


回答1:


Here I have done with this way, my string was "01/02/2012 10:45:22Am"

after using this formula:

Formula = ToText({report_;1.FirstYearDate}, "yyyy")

I have got this value :2012




回答2:


try this way

Year(Cdatetime(<<your date time value here>>));



回答3:


Try this

Year (DateValue ({Orders.Order Date}))

Here for example date field is Order date from Orders table.




回答4:


Thank you. My reporting scenario had - {Orders.POST_DATE} in minimum(YearToDate) to maximum(LastFullMonth).

That was working fine until it was run in a new year. Then Crystal read the dates as the last day of last month and the first day of the new year.

After seeing the solution here. I modified my code this way, which works:

{Orders.POST_DATE} in DateSerial(Year (minimum(LastFullMonth)), 1,1) to maximum(LastFullMonth) which now forces the 1/1/yyyy to be the same year as the year in LastFullMonth.



来源:https://stackoverflow.com/questions/22401613/extracting-only-year-value-in-crystal-report-datetime-field

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