Combines the selected date and selected time from two DateTimePicker controls - CSharp System.Windows.Forms

CSharp examples for System.Windows.Forms:DateTimePicker

Description

Combines the selected date and selected time from two DateTimePicker controls

Demo Code


using System.Globalization;
using System.Windows.Forms;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*w  ww .ja v a  2 s.  c o m*/

public class Main{
        // -------------------------------------------------------------------------------
        // GetDateFromDateTimePickers
        // Combines the selected date and selected time from two DateTimePicker controls
        // -------------------------------------------------------------------------------
        public static DateTime GetDateFromDateTimePickers(DateTimePicker oDate, DateTimePicker oTime)
        {
            DateTime oDateTime = new DateTime(
                 oDate.Value.Year,
                 oDate.Value.Month,
                 oDate.Value.Day,
                 oTime.Value.Hour,
                 oTime.Value.Minute,
                 oTime.Value.Second);

            return oDateTime;
        }
}

Related Tutorials