2

I need to construct a DateTime object with the date coming from a calendar and the hours/mins/am-pm coming from three drop down lists.

The DateTime is being inserted into a DB as a regular DateTime SQL Server DB type. I'll use something like string dt = String.Format("{0:g}", DateTime.Now); to parse it when grabbing it from the DB.

I just need to find an elegant way to construct the DateTime object for the DB insertion.

2 Answers 2

4

Why not use the standard DateTime constructor overload detailed here (MSDN).

DateTime dateTime = new DateTime(year, month, day, hour, minute, second);

Where you grab the year, month, day from your calendar, and the hour, minute, second values from parsed drop down values.

1
  • Great... forgot that I could just zero out the seconds in the constructor. Will mark as answer in a few :) Mar 7, 2012 at 2:35
0

There are a number of built-in constructor overloads for DateTime() that already do everything you need and will build a DateTime based on various inputs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.