Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
HI all ,
i have a very small problem in asp.net mvc.

i am using jquery date picker to select date which has format of mm/dd/yyyy. but when i submit the form Model count this format as dd/mm/yyyy and which creates a problem for dates which are greater than 12. i.e. it treats it as a month and throw exception that date is not valid. please tell me what setting do i need to do inside model to set particular format.
Posted

you can set the format for calender in jquery as follows
C#
$('#StartDate').datepicker({       
        dateFormat:"dd/mm/yy"
    });
 
Share this answer
 
v2
Comments
ravikhoda 24-Feb-14 6:54am    
yes it did work but we want jquery date in us format only.so we need something which work on model side.
R-a-v-i-k-u-m-a-r 24-Feb-14 7:08am    
First change the date format to dd/mm/yyyy as shown in code,Then after posting model, in action result you can convert to required format.
eg: string date = DateTime.Now.ToString("mm/dd/yyyy");
ravikhoda 24-Feb-14 7:13am    
let me try but i think when i submit form it do not change the value of that field if date is greater than 12. so it do not reach till controller...if date is less than 12 than it update the value to controller.
XML
<script type="text/javascript">
        $(document).ready(function () {

            $("#TxtBoxDate").datepicker({dateFormat:"dd/mm/yyyy" });
        });
    </script>
 
Share this answer
 
Comments
ravikhoda 24-Feb-14 7:01am    
yes it did work but we want jquery date in us format only we need to show date format as mm/dd/yyyy on textbox so we cant do as your suggestion. we need something which work on model side.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900