<asp:TextBox ID="txtDateOfBirth" runat="server" CssClass="textbox" MaxLength="10"></asp:TextBox>
<ajaxToolKit:CalendarExtender ID="CalendarExtender5" runat="server" Format="dd/MM/yyyy"
TargetControlID="txtDateOfBirth">
</ajaxToolKit:CalendarExtender>
<ajaxToolkit:FilteredTextBoxExtender ID="fltertxtDateOfBirth" runat="server"
TargetControlID="txtDateOfBirth" FilterType="Custom" ValidChars="1234567890/" />
string CommonDate = GetDateFormatYYYYMMDD(txtDateOfBirth.Text);
string GetDateFormatYYYYMMDD(string Str_ddmmyyyy)//Input dd/mm/yyyy out put will be YYYY/MM/dd
{
string newDate = null;
string yyyy = string.Empty;
string MM = string.Empty;
string dd = string.Empty;
if (Str_ddmmyyyy == null || Str_ddmmyyyy.Trim() == string.Empty)
{
newDate = null;
}else
{
if(Str_ddmmyyyy.Length>=10)
Str_ddmmyyyy = Str_ddmmyyyy.Trim().Substring(0, 10).Trim();
}
if (Str_ddmmyyyy.Contains("/"))
{
yyyy = Str_ddmmyyyy.Trim().Split('/')[2].ToString();
MM = (Str_ddmmyyyy.Trim().Split('/')[1].ToString().Length == 1) ? "0" + Str_ddmmyyyy.Trim().Split('/')[1].ToString() : Str_ddmmyyyy.Trim().Split('/')[1].ToString();
dd = (Str_ddmmyyyy.Trim().Split('/')[0].ToString().Length == 1) ? "0" + Str_ddmmyyyy.Trim().Split('/')[0].ToString() : Str_ddmmyyyy.Trim().Split('/')[0].ToString();
newDate = yyyy + "/" + MM + "/" + dd;
// newDate = dd + "/" + MM + "/" + yyyy;
}
else if (Str_ddmmyyyy.Contains("-"))
{
yyyy = Str_ddmmyyyy.Trim().Split('-')[2].ToString();
MM = (Str_ddmmyyyy.Trim().Split('-')[1].ToString().Length == 1) ? "0" + Str_ddmmyyyy.Trim().Split('-')[1].ToString() : Str_ddmmyyyy.Trim().Split('-')[1].ToString();
dd = (Str_ddmmyyyy.Trim().Split('-')[0].ToString().Length == 1) ? "0" + Str_ddmmyyyy.Trim().Split('-')[0].ToString() : Str_ddmmyyyy.Trim().Split('-')[0].ToString();
newDate = yyyy + "/" + MM + "/" + dd;
//newDate = dd + "/" + MM + "/" + yyyy;
}
else if (Str_ddmmyyyy.Contains("."))
{
yyyy = Str_ddmmyyyy.Trim().Split('.')[2].ToString();
MM = (Str_ddmmyyyy.Trim().Split('.')[1].ToString().Length == 1) ? "0" + Str_ddmmyyyy.Trim().Split('.')[1].ToString() : Str_ddmmyyyy.Trim().Split('.')[1].ToString();
dd = (Str_ddmmyyyy.Trim().Split('.')[0].ToString().Length == 1) ? "0" + Str_ddmmyyyy.Trim().Split('.')[0].ToString() : Str_ddmmyyyy.Trim().Split('.')[0].ToString();
newDate = yyyy + "/" + MM + "/" + dd;
//newDate = dd + "/" + MM + "/" + yyyy;
}
return newDate;
}
No comments:
Post a Comment