0

I'm trying to get todays datetime (YYYY-MM-DD) to show up as default in my box where I choose date. Any ideas what I can do to show the MAX part as todays date by default. Guess I can create a variable and set it to today's date and use it but are there any easier way, like I'm trying to do it with a max="something"??

 <input type="date" asp-for="MovingAverageViewModel.StartDate" id="StartDateAnvanceradSMA" value="MovingAverageViewModel.StartDate" class="form-control" max="DateTime.Now.ToShortDateString();" min="2017-01-01" /> 
4
  • 1
    Not related by remove value="MovingAverageViewModel.StartDate" (never set the value attribute when using a TagHelper - its already done by the helper). And to format it as yyyy-MM-dd then use DateTime.Today.ToString("yyyy-MM-dd") Commented Feb 26, 2018 at 10:41
  • the value="MovingAverageViewModel.StartDate" I used as I have multiple boxes with input choices so to know which box this is refering to? Do I need to write the it like max="DateTime.Today.ToString("yyyy-MM-dd")" or do I need to use any sort of (); ? Thanks for the help Commented Feb 26, 2018 at 10:50
  • asp-for="MovingAverageViewModel.StartDate" means you binding to the value of your property which add the value attribute (do not set it yourself under any circumstances). As for the maxdate - try it ) Commented Feb 26, 2018 at 11:02
  • 1
    Thanks Stephen, this syntax did the trick: max="@DateTime.Today.ToString("yyyy-MM-dd")" Commented Feb 26, 2018 at 11:43

1 Answer 1

4

Thanks Stephen, the answer: max="@DateTime.Today.ToString("yyyy-MM-dd")"

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.