Parse and format date in c#
when use '/' in pattern, must use '\' to escape it,
when get formatted date string, use the following method:
datefrom.ToString("yyyy-MM-dd")
1: DateTime datefrom;
2: try
3: {
4: datefrom = DateTime.ParseExact(txtFromDate.Text.Trim(), "MM\\/dd, yyyy", null);
5: }
6: catch (Exception)
7: {
8: datefrom = new DateTime(1900, 1, 1);
9: }
Tao obeys its own
inherent Nature