How to calculates number of days till deadline

Hi! I want to understand how to identify the date of the deadline in the text. My idea is retrieving number of days till deadline and after that sum it to the current day using python datetime. But I have mistakes, I’m trying to use similar prompts to do it "Today is Tuesday. Task deadline is Friday. Deadline date is today + X. X is ". It works when the deadline within the week, but it breaks when I’m adding Next Friday. Could you help me in such question?

1 Like

My experience is the same (albeit probably a different setup).

“Next Friday” ended up being interpreted as “this coming Friday”.


What worked for me was saying “a week on Friday” (which to be fair, is much less ambiguous)


NB I’m using a local function to perform date maths here, I’m not risking hallucination on calculations …

The OpenAI ChatGPT model is very good at many things, but performing calculations, such as the difference between two days, is very hard for the model.

Although you might get correct answers sometimes, in my experience, the performance is sufficiently random that I would not rely on it. To get this functionality, I would recommend calling a function, which accepts the two days as parameters. Below is some background on how to call functions:

Function Calling


Even then it’s a little tricky.

I have a generic calculate function and that’s only as good as the query.

The challenge here is providing sufficient number of functions with the “most suitable” type of parameters to suit a specific question.

You can end up with a lot of functions!

1 Like

Agree @merefield, a big part of the “art” of developing LLM applications is balancing too few functions at the expense of reply quality, and too many functions at the expense of application complexity.

1 Like

I would use the model to extract the date as a string, and then use regular scripting to parse the date.
The prompt might be something like:

This document describes a date of a deadline. Your task is to find this date, and print it out in ISO format.
Today is 2024-02-12.
Print out only the ISO format date of the deadline as described in this document:
{{ Document }}

Then you can parse the date using whatever function is available in your language of choice.

1 Like

If you want to see an example of how to implement a function similar to the one that @jwatte is recommending, take a look at the


function in the Office365 Toolkit (Prototype - Line 154, Implementation - Line 391) for the OpenAI Assistant API.

The function accepts an email thread and returns the formatted dates when an email sender is proposing to meet.

1 Like

This solution works quite well, but also has problems when the deadline is several weeks, or on the last Friday of the month, and also has problems with leap years even after prompting. Do you hear something about similar issues?

Yes, it is common that prompts will require modification to support corner cases like the ones you mention. My recommendation to improve prompts is to prompt the model with something like the following when it makes a mistake:

The document proposed [DATE] but you returned [DIFFERENT DATE], how would you change the prompt to avoid this problem in the future