0

I'm trying to set default value for text input, but when doing this

<input type="text" id="dateTo" name="to" class="datepick" value="@DateTime.Now.ToString("yyyy-mm-dd")" />

i'm getting some like this 2015-41-26

and when i'm set jquery picker time format like this

$(function () {
    $(".datepick").datepicker({ gotoCurrent: true, dateFormat: "yy-mm-dd", firstDay: 1 });
});

date format - like a this 2015-01-26 (TG with correct date)

How to solve both piece of one problem with datepicker.

2
  • Q: Why 4 digit and 2 digit years? Why not just 4 digit years for both? Commented Jan 26, 2015 at 15:35
  • 1
    To mock up a repro, can you do a save-as from your browser of the page's raw HTML and stick it in a JSFiddle? That will help testing the date-picker problem (please fix the mm => MM first) Commented Jan 26, 2015 at 15:37

1 Answer 1

2

Server-side mm is the minutes, not the months :)

In .Net a 2 digit month is MM (capital Ms).

e.g. change it to:

@DateTime.Now.ToString("yyyy-MM-dd")
Sign up to request clarification or add additional context in comments.

1 Comment

You are right(i get lost it) - but when i select a datepicker i getting exception like this Exception was thrown at line 19, column 49713 in http://localhost:46960/Scripts/jquery-1.5.1.min.js 0x800a139e - JavaScript runtime error: SyntaxError may be this happened because dateFormat: "yy-mm-dd" != "@DateTime.Now.ToString("yyyy-MM-dd")

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.