Convert String Value to Date Value Or Null - CSharp System

CSharp examples for System:DateTime

Description

Convert String Value to Date Value Or Null

Demo Code


using System.Text;
using System.IO;/*from   w ww.jav a2s  . c o  m*/
using System.Globalization;
using System.Collections.Generic;
using System;

public class Main{
        public static System.DateTime? DateValueOrNull(this string value)
        {
            System.DateTime result;
            if (System.DateTime.TryParse(value, out result))
            {
                return result;
            }
            else
            {
                return null;
            }

        }
}

Related Tutorials