skip to Main Content

I want to refine my value today but i cant set. Can help me!

<input type="date" name="start" value="2022-12-25"/>
<input type="date" name="end" value="2022-12-25"/>

I want to refine my value today but i cant set. Can help me!

2

Answers


  1. the information you provided is not sufficient. Provide which language/technology you are working, i figured it out that you are looking for help in Microsoft technology stack.

    Coming to the point you want to print/show Current Datetime value, for that, According to me Create variable storage Current Datetime and bind it to the Html

    for Ex.

    var CurrentDateTime = DateTime.now;
    

    this will set Current date time to the variable and in HTML MVC if you are using razor view / pages
    you just need to bind that value to it.
    there are multiple ways for that.
    but here i would like to GO with ViewBag approach
    you can do like following

    ViewBag.CurrentDatetime =  DateTime.Now;
    

    And in your UI cshtml file
    retrieve that stored value from ViewBag like following

    @{
        var CurrentDatetime = ViewBag.CurrentDatetime;
     }
    
    <input type="date" name="end" value=@CurrentDatetime/>
    

    Note: If you not find this answer Helpful, i am requesting you to Provide some Detailed and precise Explanation regarding what you exactly looking for.

    Thanks.

    Login or Signup to reply.
  2. You can try to set the default date with js:

    <input type="date" name="start" />
    <input type="date" name="end" />
    
    
    @section Scripts{
    
    <script>
        $(function(){
                document.getElementsByName('start')[0].valueAsDate = new Date();
                document.getElementsByName('end')[0].valueAsDate = new Date();
    
        })
    </script>
    }
    

    result:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search