Convert a date to a string. If date is null, return a null string. - CSharp System

CSharp examples for System:DateTime Convert

Description

Convert a date to a string. If date is null, return a null string.

Demo Code


using System.Globalization;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//from  ww w.  j  av a 2 s  .  c  o m

public class Main{
        /// <summary>
        /// Convert a date to a string. If date is null, return a null string.
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static string DateToString(DateTime? date)
        {
            if (date == null) return null;
            return Convert.ToString(date);
        }
}

Related Tutorials