DateTime From Year Month Day - CSharp System

CSharp examples for System:DateTime Year

Description

DateTime From Year Month Day

Demo Code


using System;/*www. jav a  2  s  .c  om*/

public class Main{
        public static DateTime? FromYearMonthDay(int year, int month, int day)
        {
            if (month > 12 || month < 1 || day > 31 || day < 1) return null;

            try
            {
                return new DateTime(year, month, day);
            }
            catch
            {
                return null;
            }
        }
}

Related Tutorials