Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make the date picker start with dd.mm.yyyy instead of 01.01.0001

So i have made a datepicker that keeps the date that some have change it to, but the problem is that i dont like that it starts with 01.01.0001 when you get on that page.

Like this:
https://imgur.com/a/rOYTqra

This is my datepicker code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<form method="post" asp-page-handler="TestClick">
    <br />
    <br />
    <input asp-for="Date" />
    
    <button>Search</button>
    <br />
    </form>

from my .cshtml file

[BindProperty, DataType(DataType.Date)]
        public DateTime Date { get; set; }

public void OnPostTestClick()
        {
            String testDate = Request.Form["Date"];
            Debug.WriteLine("Testclick verdi2 = " + testDate);
            filterdato = testDate;
            ListData();
        }

from my .cshtml.cs file.

I was wondering if there was a way for me to still have the function of keeping the dates when someone changes it in the datepicker, but also have the datepicker start with "dd.mm.yyyy" once you enter the page?

>Solution :

The default value of DateTime is 01.01.0001. Make your DateTime property nullable (DateTime?) so that default value is null:

public DateTime? Date { get; set; }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading