Extract or Handle week to date (WTD), month to date (MTD), year to date(YTD)

Hi Folks,

I want to extract the dates form the text like :

  • week to date / wtd as
    date1 = starting date of this week
    date2 = today’s date

  • month to date / mtd as
    date1 = starting date of the this month date2 = today’s date

  • year to date / ytd as
    date1 = starting date of this year
    date2 = today’s date

I have tried to extract using duckling but duckling is not able to extract the dates. I am trying to handle the dates in the custom action, so if I know the duckling output and the granularity as week, month or year I am calculating the date 2 accordingly. Since on parsing these statements duckling is not able to give me any information. Kindly help to figure out this!

My end goal is:

If user is asking the bot :

User : What is my sales wtd ( week to date)

Bot : Calculate the sales between the date1 as starting date of this week and date 2 as today’s date

Note - It would be really great if more queries like last week same day/ last month same day/ last year same day could be also handled!

I hope I am making sense over here!

Any help would be really appreciated.



@souvikg10 @akelad Kindly help!

Duckling manages date dimensions which are generally used in proper english. What you are describing here is very genre specific , a custom dimension. you can add these rules in duckling as a custom dimension

for the life of me, i still haven’t figured why they wrote duckling in Haskell, so it is hard for me to understand it.

however you can also try lookup table and add these wtd,mtd,ytd as entities and just do calculations in your code itself.

if entity == "wtd":