Question Problem in setting DateTime value explicitly.

priyamtheone

Well-known member
Joined
Sep 20, 2007
Messages
96
Programming Experience
Beginner
I want to pick a value from a DateTimePicker in 'MM/dd/yyyy hh:mm tt' format, add 00 as second with it, store it in a DateTime variable and save it to database. Suppose if I pick the value 05/28/2010 9:25 AM or 05/28/2010 9:25:34 AM from the DateTimePicker, it'll be stored in the variable and saved to database as 05/28/2010 9:25:00 AM irrespective of what value is chosen from the DateTimePicker for second. I'm using the following statement but it's getting failed during the format conversion while storing it in the DateTime variable generating an error.

Dim dtmReminderTime As DateTime
dtmReminderTime = DateTime.Parse(Format(dtpReminderTime.Value, "MM/dd/yyyy hh:mm") + ":00 " + Format(dtpReminderTime.Value, "tt"))

I tried the other way but failed:
dtmReminderTime = Convert.ToDateTime(Format(dtpReminderTime.Value, "MM/dd/yyyy hh:mm") + ":00 " + Format(dtpReminderTime.Value, "tt"))

I have also tried using culture specific information but of no avail. Please help.
 
reset seconds to 0:
VB.NET:
Dim d As Date = dtpReminderTime.Value
d = d.AddSeconds(-1 * d.Second)
 
Back
Top