Reading value like <YYYY><MM><DD> from DB, passing this value in to my date format like ("YYYYmmdd")
date = DateTime.Now;
YYMMVal = date.ToString(DateFormat);
I was using replace function to get my dateformat like below
strDateFormat = strDTF.ToString();
string LessThanFormat = strDateFormat.Replace("<", "");
string greaterThanFormat = LessThanFormat.Replace(">", "");
String yearFormats = greaterThanFormat.Replace("Y", "y");
String MonthFormat = yearFormats.Replace("m", "M");
string DateFormat = MonthFormat.Replace("D", "d");
or
StringBuilder srtbDateFormat = new StringBuilder(strDateFormat);
srtbDateFormat.Replace("<", "");
srtbDateFormat.Replace(">", "");
srtbDateFormat.Replace("Y", "y");
srtbDateFormat.Replace("m", "M");
srtbDateFormat.Replace("D", "d");
YYMMVal = date.ToString(srtbDateFormat.tostring());
What's the efficient way to replace the above string and match with date format?
"<YYYY><MM><DD>"is the input string and"YYYYmmdd"is the output string that you want?