C# provides data Annotation features. For example, a date needs to be stored in the dd/mm/yy in database & while displaying it in the format dd/mm/yyyy with some built in functions and without any manual conversion.
Here is the Model defined that you can use in your project:
- public class Example
- {
- string _date = "50612";
- public string date
- {
- get
- {
-
- DateTime dt = DateTime.ParseExact(this._date, "ddMMyy", System.Globalization.CultureInfo.InvariantCulture);
- return dt.ToString("dd MMM yyyy");
- }
- set
- {
- DateTime dt = DateTime.ParseExact(value, "dd MMM yyyy", System.Globalization.CultureInfo.InvariantCulture);
- this._date = dt.ToString("ddMMyy");
- }
- }
- }