manoj150
on Jan 16, 2017 07:30 AM
11185 Views
Here is the datepicker:
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.16/jquery-ui.js" type="text/javascript"></script>
<link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.16/themes/humanity/jquery-ui.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript">
var $ = jQuery.noConflict();
$(function () {
$("[id$=txtExpDate]").datepicker({
//dateFormat: 'DD, d MM, yy',
// dateFormat: 'mm-dd-yy',
//buttonImageOnly: true,
//buttonImage: 'http://jqueryui.com/demos/datepicker/images/calendar.gif'
});
});
$(function () {
$("[id$=txtManDate]").datepicker({
//dateFormat: 'DD, d MM, yy',
// dateFormat: 'mm-dd-yy',
//buttonImageOnly: true,
//buttonImage: 'http://jqueryui.com/demos/datepicker/images/calendar.gif'
});
});
</script>
Here is the code for convert:
DateTime dt2 = Convert.ToDateTime(txtManDate.Text);
DateTime dt3 = Convert.ToDateTime(txtExpDate.Text);
The server database i am using for insert value..this working very well in local code...but not working in server.
Error is:
String was not recognized as a valid DateTime.
What should i do??
Download FREE API for Word, Excel and PDF in ASP.Net:
Download
Andrea
on Jan 16, 2017 07:30 AM
1
Hi manoj150,
Your custom format is wrong. Use DateTime.ParseExact method, your format and string should match exactly.
var manDate = DateTime.ParseExact(txtManDate.Text, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);
DateTime dt2 = Convert.ToDateTime(manDate);
var expDate = DateTime.ParseExact(txtExpDate.Text, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);
DateTime dt3 = Convert.ToDateTime(expDate);
After you parse your string, you can format whatever format you want with DateTime.ToString() method.
This is not working any other method..??
same error.
Hi manoj150,
1) Change the datetime format of your server from
Control Panel -> Regional and Language Options -> Advanced
2) Open IIS and follow below steps:
- Click on you Website
- Select .NET GLOBALIZATION option
- From Culture tab, select required Culture and UI Culture.
- Finally iisreset.