EDN Admin
Well-known member
Dear All
I had made one report in our application, its working fine but some time when I select the few date that time its giving the format exception error like(The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar.)
The Date which I selected in DateTime Picker is: 5/24/2011.
I am also seding the code which I used to convert the date format:
<span style="font-size:x-small; color:#008080 <span style="font-size:x-small; color:#008080 <font size="2" color="#008080" style="font-size:x-small; color:#008080
IFormatProvider
</font>
<span style="font-size:x-small formats = <span style="font-size:x-small; color:#0000ff <span style="font-size:x-small; color:#0000ff new<span style="font-size:x-small System.Globalization.<span style="font-size:x-small; color:#008080 <span style="font-size:x-small; color:#008080 CultureInfo<span style="font-size:x-small (<span style="font-size:x-small; color:#800000 <span style="font-size:x-small; color:#800000 "en-US"<span style="font-size:x-small ,
<span style="font-size:x-small; color:#0000ff <span style="font-size:x-small; color:#0000ff true<span style="font-size:x-small );<br/>
string frombookdate = null;<br/>
string origindates = null;<br/>
//string destinationdates = null;<br/>
origindates = datetime_Picker.Text.ToString();<br/>
DateTime dsdates = default(DateTime);<br/>
string[] contents = new string[4];<br/>
char splitterss = ;<br/>
splitterss = /;<br/>
contents = origindates.Split(splitterss);
if ((contents[0].Length == 1 & contents[1].Length == 1))<br/>
{<br/>
dsdates = DateTime.ParseExact(datetime_Picker.Text, "d/M/yyyy", formats);<br/>
}<br/>
else if ((contents[0].Length == 2 & contents[1].Length == 1))<br/>
{<br/>
dsdates = DateTime.ParseExact(datetime_Picker.Text, "dd/M/yyyy", formats);<br/>
}<br/>
else if ((contents[0].Length == 1 & contents[1].Length == 2))<br/>
{<br/>
dsdates = DateTime.ParseExact(datetime_Picker.Text, "d/MM/yyyy", formats);<br/>
}<br/>
else<br/>
{<br/>
dsdates = DateTime.ParseExact(datetime_Picker.Text, "dd/MM/yyyy", formats);<br/>
}<br/>
int ms = dsdates.CompareTo(DateTime.Today);
int dds = 0;<br/>
int mms = 0;<br/>
int yys = 0;<br/>
dds = dsdates.Day;<br/>
mms = dsdates.Month;<br/>
yys = dsdates.Year;
frombookdate = yys.ToString() + "-" + mms.ToString() + "-" + dds.ToString();
Please help me to solve this issues.
Thanks and regards
Amit <hr class="sig Amit
View the full article
I had made one report in our application, its working fine but some time when I select the few date that time its giving the format exception error like(The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar.)
The Date which I selected in DateTime Picker is: 5/24/2011.
I am also seding the code which I used to convert the date format:
<span style="font-size:x-small; color:#008080 <span style="font-size:x-small; color:#008080 <font size="2" color="#008080" style="font-size:x-small; color:#008080
IFormatProvider
</font>
<span style="font-size:x-small formats = <span style="font-size:x-small; color:#0000ff <span style="font-size:x-small; color:#0000ff new<span style="font-size:x-small System.Globalization.<span style="font-size:x-small; color:#008080 <span style="font-size:x-small; color:#008080 CultureInfo<span style="font-size:x-small (<span style="font-size:x-small; color:#800000 <span style="font-size:x-small; color:#800000 "en-US"<span style="font-size:x-small ,
<span style="font-size:x-small; color:#0000ff <span style="font-size:x-small; color:#0000ff true<span style="font-size:x-small );<br/>
string frombookdate = null;<br/>
string origindates = null;<br/>
//string destinationdates = null;<br/>
origindates = datetime_Picker.Text.ToString();<br/>
DateTime dsdates = default(DateTime);<br/>
string[] contents = new string[4];<br/>
char splitterss = ;<br/>
splitterss = /;<br/>
contents = origindates.Split(splitterss);
if ((contents[0].Length == 1 & contents[1].Length == 1))<br/>
{<br/>
dsdates = DateTime.ParseExact(datetime_Picker.Text, "d/M/yyyy", formats);<br/>
}<br/>
else if ((contents[0].Length == 2 & contents[1].Length == 1))<br/>
{<br/>
dsdates = DateTime.ParseExact(datetime_Picker.Text, "dd/M/yyyy", formats);<br/>
}<br/>
else if ((contents[0].Length == 1 & contents[1].Length == 2))<br/>
{<br/>
dsdates = DateTime.ParseExact(datetime_Picker.Text, "d/MM/yyyy", formats);<br/>
}<br/>
else<br/>
{<br/>
dsdates = DateTime.ParseExact(datetime_Picker.Text, "dd/MM/yyyy", formats);<br/>
}<br/>
int ms = dsdates.CompareTo(DateTime.Today);
int dds = 0;<br/>
int mms = 0;<br/>
int yys = 0;<br/>
dds = dsdates.Day;<br/>
mms = dsdates.Month;<br/>
yys = dsdates.Year;
frombookdate = yys.ToString() + "-" + mms.ToString() + "-" + dds.ToString();
Please help me to solve this issues.
Thanks and regards
Amit <hr class="sig Amit
View the full article