Search code examples
c#notion-api

how do I remove time from calendar database in Notion API using C#?


I made a code that receives date and plan from a user and uploads the data to Notion database. I succeeded on displaying the data into the Notion calendar page, however the time keeps appearing. I wanted it to show up as "yyyy-mm-dd" but instead, it shows up as "yyyy-mm-dd 12:00 AM(UTC)" this is a part of my xaml.cs

        public Calendar()
    {

        //MessageBox.Show(sel_p);
        var _client = NotionClientFactory.Create(new ClientOptions
        {
            AuthToken = TOKEN.Token
        });

        PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput
        {
            DatabaseId = TOKEN.Calendar_ID
        })

                      .AddProperty("plan", new TitlePropertyValue
                      {
                          Title = new List<RichTextBase>
                          {
                             new RichTextText
                             {
                                 Text = new Text
                                 {
                                    // Content = "test_2"
                                    Content = _111.plannn
                                 }
                             }
                          }
                      })
                       .AddProperty("date", new DatePropertyValue
                       {
                           Date = new Date
                           {
                               //Start = DateTime.Parse("2022 06 16")
                               //Start = _111.datee
                               
                           }
                           

                       })

                     .Build();

        var page = _client.Pages.CreateAsync(pagesCreateParameters);

    }

    public string aaa = "";
    public string[] test = { };
    string[] tototo = new string[6];
    int a = 0;
    public async Task asdadsasd()
    {

        var _client = NotionClientFactory.Create(new ClientOptions
        {
            AuthToken = TOKEN.Calendar_ID
        });
        var users = await _client.Users.ListAsync();

        var dsds = users.Results.Select(x => x.Name).Distinct();

        foreach (var item in dsds)
        {

            tototo[a] = item;
            TOKEN.aaaa[a] = tototo[a];
            ++a;
            //MessageBox.Show(item);

        }
    }
}

}


Solution

  • I have a date column (called DateOne) in one of my databases and it displays the date and time. To make it display only the date, I have to add another column (called DateTwo) with type = Formula. I then apply the following formula to remove the time:

    formatDate(prop("DateOne"), "MMMM D, YYYY")
    

    Next, I hide the column called DateOne and only show DateTwo.

    Hope this answers the question and works for you.