Profits of Last Month, Date operations
Application Type
Mobile
Service Studio Version
11.10.16 (Build 40208)
Platform Version
11.11.2 (Build 28863)

I'm trying to get the profits of the last month, but I'm having problems with the date operations.
Does anyone know what the problem might be ?

Thanks in advance !

the code should get me the dates of last month.


DiffMinutes(Basket.DateTime,NewDateTime( Year(CurrDate()), Month(CurrDate()), 1,0,0,0))>1 and
DiffMinutes(Basket.DateTime,AddMonths(NewDateTime( Year(CurrDate()), Month(CurrDate()), 1,0,0,0),-1))<1
mvp_badge
MVP

Hi Kalmar,


You can do:

DateTimeToDate(Basket.DateTime) <= DateTimeToDate(AddDays(NewDate(1,Month(CurrDate()), Year(CurrDate())),-1)) and
DateTimeToDate(Basket.DateTime) >= NewDate(1, Month(AddMonths(CurrDate(), -1)), Year(AddMonths(CurrDate(), -1)))


The first condition checks the last day of the previous month and the second condition the first day of the previous month.


Hope it helps.


Kind Regards,
João

Well this is not working either, there was an error with parameter order, but thanks anyway. I'll keep trying.

mvp_badge
MVP

Hi,


My mistake. I had set my dates with day, month, year when it should be year, month, day, that's why the order was swapped. Just exchanging the parameters order in the NewDate function should do the trick.

DateTimeToDate(Basket.DateTime) <= DateTimeToDate(AddDays(NewDate(Year(CurrDate()),Month(CurrDate()), 1),-1)) and
DateTimeToDate(Basket.DateTime) >= NewDate(Year(AddMonths(CurrDate(), -1)), Month(AddMonths(CurrDate(), -1)), 1)


Hi Kalmar,

you can try this to get the first and last day of the previous month.

first-day-of-previous-month -> 

NewDate(

Year(AddMonths(CurrDate(),-Month(CurrDate()))),

Month(AddMonths(CurrDate(),-Month(CurrDate()))),

1)

Note: 

from current date, add -1 month and from that get the year and month

the create the new date with the above values plus 1 that is the first day


last-day-of-previous-month -> AddDays(CurrDate(),-Day(CurrDate()))

Note: just subtract the current day from the current date that you will get the last day of the previous month.

Hope it helps you

Best Regards


Hi @Kalmar Martin 

Try this approach

Regards

Gonçalo Almeida

Hi Kalmar,

You can try this:

DateTimeToDate(Basket.DateTime) >= NewDate(Year(AddMonths(CurrDate(),-1)), Month(AddMonths(CurrDate(),-1)), 1)
and 
DateTimeToDate(Basket.DateTime) < NewDate(Year(CurrDate()), Month(CurrDate()), 1)

With that you check if your date is equal or greater than the first day of the past month

and 

if your date is less than the first day of the current month.

Hope it helps.

Regards.


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.