Hi @Darshan Saini ,
What is your exact requirement, count total for previous month ? If so, why say 1 - 30 in your question, not every month has 30 days. Anyway, none of the above solutions will work.
The solution of @Mayank Dharmpurikar and @Md Mansur will be wrong all the time once you have data in your database covering more than a year, for example if in may, it will count all data in april, of all years. It will also not work in janurary, as it will then be trying to find records for month 0.
The solution of @Akshay Deshpande š will work more often, but will still be wrong some of the time. As the other, it will fail in january as it will try to compose a newdate with a month value of 0. It will fail in march as it is trying to compose the date of february 30th. These failures will probably be throwing exceptions. It will also return incorrect counts if there are records to be counted on the last day of the month, as it is using DateToDateTime on the last day, this has a time portion of 00:00, not 23:59.
See attached oml for a solution. When dealing with datetimes in a reactive app, you get the added bonus of having to deal with difference of timezone between end user and server. See difference between the almost correct and the correct solution in my oml. If you define the start and end of month in end user perspective, you would have to calculate boundery datetimes of your query on the client, or make allowences for the difference in timezone in your server logic.
Dorine