user5567987
user5567987

Reputation: 167

how to save two data on one cell Date and time

i have two Datetimepicker. One is formatted as Date, and the other one is formatted as Time. Now i have database which have 3 columns: ID, Name, and Schedule. I want to save the date and time in the schedule column formatted like this mm/dd/yyyy hh:mm AM/PM

What datatype should i use in schedule column?

Upvotes: 0

Views: 61

Answers (1)

Postonoh
Postonoh

Reputation: 60

Combining (concatenating) date and time into a datetime

using System;
using System.Globalization;

public class Test
{
    public static void Main()
    {
     string one = "13/02/09";
     string two = "2:35:10 PM";

     DateTime dt = Convert.ToDateTime(one + " " + two);
     DateTime dt1 = DateTime.ParseExact(one + " " + two, "dd/MM/yy h:mm:ss    tt", CultureInfo.InvariantCulture);

            Console.WriteLine(dt1);
    }
}

Upvotes: 0

Related Questions