Hey folks! I’m working on a C# project that adds events to a Notion calendar database. Everything’s working fine, except for one annoying detail: the time keeps showing up in my entries.
I want the dates to appear as ‘yyyy-mm-dd’, but they’re coming out as ‘yyyy-mm-dd 12:00 AM(UTC)’. It’s driving me nuts!
Here’s a snippet of my code:
PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput
{
DatabaseId = myCalendarId
})
.AddProperty("eventName", new TitlePropertyValue
{
Title = new List<RichTextBase>
{
new RichTextText
{
Text = new Text
{
Content = userInput.EventName
}
}
}
})
.AddProperty("eventDate", new DatePropertyValue
{
Date = new Date
{
Start = userInput.EventDate
}
})
.Build();
var newPage = await notionClient.Pages.CreateAsync(pagesCreateParameters);
Any ideas on how to strip out that pesky timestamp? Thanks in advance!
hey there! i ran into this too. what worked for me was using a formula property in notion to format the date. you can keep ur c# code as is, but add a formula in notion like formatDate(prop(“eventDate”), “yyyy-MM-dd”). this’ll show just the date without the time stuff. hope that helps!
I’ve dealt with this exact issue in my Notion integration projects. The root of the problem is that Notion’s API always expects a full datetime, even when you’re just trying to add a date-only event.
One workaround I’ve found effective is to set the time to midnight UTC when creating the event. This way, it’ll display as just the date in most cases. Here’s how you can modify your code:
.AddProperty("eventDate", new DatePropertyValue
{
Date = new Date
{
Start = userInput.EventDate.Date.ToString("yyyy-MM-ddT00:00:00Z")
}
})
This approach ensures that you’re sending a complete datetime to Notion, but it’ll typically render as just the date in the UI.
Another option, if you have control over the Notion database structure, is to add a formula property that formats the date how you want it. This gives you more flexibility in how dates are displayed without changing your C# code.
I encountered a similar issue while integrating Notion’s API in a C# project. The problem comes from Notion expecting a full ISO 8601 datetime, which is why you see a default time included. One solution is to explicitly format your date to include time, as shown in this snippet:
.AddProperty("eventDate", new DatePropertyValue
{
Date = new Date
{
Start = userInput.EventDate.Date.ToString("yyyy-MM-ddTHH:mm:ssZ")
}
})
Another approach is to use a formula property in Notion to reformat the date display. This method lets you work within Notion’s framework while ensuring that your dates appear as just the date.