|
-
May 7th, 2010, 11:19 AM
#1
[RESOLVED] Problem in setting DateTime value explicitly.
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.
-
May 7th, 2010, 06:12 PM
#2
Re: Problem in setting DateTime value explicitly.
Try this:
Code:
Dim dtmReminderTime As String
dtmReminderTime = String.Format(dtpReminderTime, "MM/dd/yyyy hh:mm:00 tt")
-
May 11th, 2010, 11:22 AM
#3
Re: Problem in setting DateTime value explicitly.
No I can't change the datatype of the variable to string. This is a good option:
Dim dtmReminderTime As DateTime
dtmReminderTime = dtpReminderTime.Value.AddSeconds(-dtpReminderTime.Value.Second)
-
May 12th, 2010, 07:16 AM
#4
Re: Problem in setting DateTime value explicitly.
priyamtheone, please use [CODE] tags when posting code.
I have asked this before, and this is the last time I'll ask.
It is explained here :
http://www.codeguru.com/forum/showthread.php?t=403073
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|