0

I tryed some code examples from here&another forums but it still gets the date with time when I click the edit button. Here's my code

   <div class="form-group">
        <label class="control-label col-md-2">License Date</label>
        <div class="col-md-10">
            @Html.EditorFor(model => model.L_Date, new { htmlAttributes = new { @class = "date-picker" } })
        </div>
</div>

<link href="@Url.Content("~/Content/themes/base/jquery-ui.min.css")" rel="stylesheet" />
<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.10.4.min.js")"></script>
@section scripts{
    <script src="~/Scripts/jquery-ui-1.12.1.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $('.date-picker').datepicker({
                showOn:"both",
                buttonText: "...",
                dateFormat: 'dd.MM.yy',
                changeYear: true,
                changeMonth: true,
                firstDay: 1
            });
        });
    </script>
}

It gives like " 2.07.2019 00:00:00 " format, I just want "2.07.2019 ". Thank you.

Isn't there anyone have same problem.Any other help ?

2 Answers 2

1

This is where and how you change the date format

$(function () {
        $('.date-picker').datepicker({
            showOn:"both",
            buttonText: "...",
            dateFormat: 'dd/MM/yy',//change format here
            changeYear: true,
            changeMonth: true,
            firstDay: 1
        });
    });

Check this for more formats. https://www.encodedna.com/jquery/ui-datepicker-widget-change-date-format.htm

Also you can change your textbox to

@Html.EditorFor(model => model.L_Date, "{0:d}", new { id = "your Id", @class="date-picker" })

EDIT

Another way to do this is to format the model before binding see my answer here

@{ 
    ViewBag.Title = "Home Page";
    Model.L_Date = Model.L_Date.ToString("d");//or any other formats
}
Sign up to request clarification or add additional context in comments.

3 Comments

I tryed this format but its still same "2.07.2019 00:00:00"
Can you use TextBoxFor to try
Sorry , I need picker not a single box
0

Try this code.Date format will be "dd/mm/yy"

 $('.date-picker').datepicker({dateFormat: 'dd/mm/yy'});

2 Comments

link href="ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/…" rel="stylesheet" /> <script type="text/javascript" src="ajax.googleapis.com/ajax/libs/jquery/1.7.1/…> <script type="text/javascript" src="ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/…> Try adding all scripts under @sectionScripts
Same ,nothing changed

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.