user85511
user85511

Reputation: 533

The string was not recognized as a valid datetime

objfile.dateFileDate=convert.ToDatetime(Format(txtdate.text,"MM/dd/yyyy hh:mm"))

following error is coming

The string was not recognized as a valid datetime .There is an unknown word starting at 0.

What should i do to save this datetime, please help

Upvotes: 0

Views: 11403

Answers (3)

Mladen Mihajlovic
Mladen Mihajlovic

Reputation: 6445

You can't format normal text using datetime formats.

Try

C#

objfile.dateFileDate=DateTime.ParseExact(txtdate.text, "MM/dd/yyyy hh:mm", null);

VB.NET

objfile.dateFileDate=DateTime.ParseExact(txtdate.text, "MM/dd/yyyy hh:mm", Nothing)

This is assuming dateFileDate is a DateTime type and that the txtdate.text is in the above format.

Upvotes: 4

EKS
EKS

Reputation: 5623

If your program is used by a international crowd, read on :)

ppl from different cultures will write dates in diffrent formats, so if your always going to parse the string that could be get sticky. Consider using the calander control? Im saying this based on personal experience. Also finding out why your current one is failing, i would do a DateTime.Now.ToString() and compare that to whats in the textbox so you can see whats curently being typed in wrong ( While debugging off course, to help track down the problem)

Upvotes: 1

Jeff Olson
Jeff Olson

Reputation: 329

Try hh:nn instead of hh:mm

I believe mm is Months in two digit format and nn is minutes in two digit format.

Upvotes: -3

Related Questions