Reputation: 15253
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.
Upvotes: 2
Views: 936
Reputation:
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.
Upvotes: 0
Reputation: 61589
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.
Upvotes: 4