Recursive AI

Add today’s date to a C# prompt template

OneLLM is a free, open-source LLM and agent library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

The date comes from your app’s clock, not a model.

Terminal
dotnet add package RecursiveAI.OneLlm

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using OneLlm.Templating;
var options = new TemplateRenderOptions
    { TimeProvider = TimeProvider.System };
Console.WriteLine(Template.Render(
    "Today: {{now | date \"2006-01-02\"}}",
    null, render: options));

2006-01-02 is a Go-style layout meaning yyyy-MM-dd, not a fixed date.

On November 29, 2026, this printed:

Text
Today: 2026-11-29

Unzip the example, then dotnet run.

The full program

The download renders the same prompt but fixes the clock at July 4, 2030, in UTC. It checks the exact string and then shows the error you get when you omit the clock. Nothing is sent to a model.

C#
using OneLlm.Templating;
 
const string prompt = "Today: {{now | date \"2006-01-02\"}}";
var clock = new FixedClock(new DateTimeOffset(
    2030, 7, 4, 9, 5, 6, TimeSpan.Zero));
var options = new TemplateRenderOptions { TimeProvider = clock };
string rendered = Template.Render(prompt, null, render: options);
if (rendered != "Today: 2030-07-04")
    throw new InvalidOperationException($"Unexpected prompt: {rendered}");
Console.WriteLine(rendered);
 
try
{
    Template.Render(prompt, null);
    throw new InvalidOperationException("Expected a missing-clock error.");
}
catch (TemplateException error)
{
    Console.WriteLine(error.Detail);
}
 
sealed class FixedClock(DateTimeOffset utc) : TimeProvider
{
    public override DateTimeOffset GetUtcNow() => utc;
    public override TimeZoneInfo LocalTimeZone => TimeZoneInfo.Utc;
}
Text
Today: 2030-07-04
error calling now: no TimeProvider was given to the render, so there is no clock

If you call now without setting TemplateRenderOptions.TimeProvider, rendering throws TemplateException; it does not silently read the system clock.

Variations

To format a timestamp you already have, pass it to date directly. No clock is required in this case.

C#
using OneLlm.Templating;
Console.WriteLine(Template.Render(
    """{{date "2006-01-02" "2030-07-04T09:05:06Z"}}""",
    null));
Text
2030-07-04

Render a prompt template · Fail on a missing prompt key


The short answer

Use {{now | date "2006-01-02"}} in the prompt and pass a TimeProvider to Template.Render. Use TimeProvider.System for the machine’s current local date. Use a fixed clock in a test so the expected string doesn’t change depending on when the test runs. Rendering produces text locally; it doesn’t call a model.

How do I add today’s date to an LLM prompt?

Use now at render time and date to keep just the calendar date. The | sends the value of now into date as its last argument. The layout 2006-01-02 is Go template syntax: it means four-digit year, two-digit month, and two-digit day. It doesn’t make the date come out as January 2, 2006. Don’t substitute the .NET format string yyyy-MM-dd; see the date entry in the template reference.

Pick the clock based on what “today” means in your application. now uses the clock’s local time, so machines in different time zones can report different dates at the same instant. The fixed clock in the download overrides both the instant and the time zone. That keeps the test independent of the computer’s clock and local zone. If you’re reporting on a date from a record rather than today, pass the record’s timestamp to date as in the variation instead of deriving a new one at render time.

All onellm recipes