skip to Main Content

I have date format in yyyy-mm-dd, I want to let user to input date if user give 2000 then append – to the date accordingly.

I have datepicker to provide date.

3

Answers


  1. Chosen as BEST ANSWER

    I achieved this without using datepicker functions, thanks for the recommendations above!.

    $("#ValidFrom").keyup(function () {
        var input = $("#ValidFrom");
        var len = $("#ValidFrom").val().length;
        alert(len);
        switch (len) {
            case 4: {
                input.val(input.val() + "-");
                break;
            }
            case 7: {
                input.val(input.val() + "-");
    
                break;
            }
    
            default: {
                break;
            }
    
        }
    
    })
    

  2. In jQuery use formatDate. docs

    $.datepicker.formatDate( "yy-mm-dd", date );
    
    Login or Signup to reply.
  3. <!DOCTYPE html>
    <html>
    
    <head>
        <title>
            How to get input type date
            in dd-mm-yyyy format ?
        </title>
        
        <style>
            body {
                text-align: center;
            }
            h1 {
                color: green;
            }
        </style>
    </head>
    
    <body>
        <h1>DateInput</h1>
        
        <h3>
            Get input date in
            dd-mm-yyyy format
        </h3>
        
        <label for="start">
            Enter the Date:
        </label>
    
        <input type="date" name="begin"
            placeholder="dd-mm-yyyy" value=""
            min="1997-01-01" max="2030-12-31">
    </body>
    
    </html>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search