I have a page where I CREATE and UPDATE an event and this event can have eventDate input calendar:
When creating an event all works great. When I update an event I pre-populate this field with the date from DB:
txtEventDate.Text = Reader.GetDateTime(7).Date.ToShortDateString();
Now, it shows nice:
05/05/2011
but the same code which worked for CREATING an event, now fails on UPDATING here:
cmd.Parameters.Add("?eventDate", MySqlDbType.DateTime).Value = DateTime.ParseExact(txtEventDate.Text + " " + txtEventTime.Text,
"MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture);
because it ‘sees’ (checked with Debug) that txtEventDate.Text has value:
5/5/2011
So the 0’s are missing…
It’s just really ugly…because in UI they are there…Do you know what can be the problem?
UPDATE: I’ve attached the photo to prove the issue…
Ps: When I do not EDIT the event (so I do not pre-populate this field but choose choose some date from calendar) all works perfectly…
First of all, for date part of a format you should specify
"mm/dd/yyyy"(with non-capital “M” letters) to ignore the leading zeroes while parsing but my concern is that the error you posted in the image does not include time and you usedDateTime.ParseExact()function with time format included.