Solved

System.FormatException: String was not recognized as a valid DateTime

Posted on 2006-10-25
7
308 Views
Last Modified: 2008-01-09
Hello Experts,

DataType in my database is DateTime. But when I try to pass the date from my model,
I am getting the above mentioned error.

There are chances of the string being null sometimes please help.

int newTaskID;
                saved = TaskDAL.Insert(task.AssignedTo.UserID, task.Subject, task.Description, Convert.ToDateTime(task.DateTime), task.NoDateTime, task.Location.LocationGroupID, task.Priority, task.Status, task.Remind, task.Minutes, task.Email, out newTaskID);
                 task.TaskID = newTaskID;
0
Comment
Question by:rowmark
7 Comments
 
LVL 12

Expert Comment

by:craskin
ID: 17807428
try using CDate() instead of Convert.ToDateTime()
0
 

Author Comment

by:rowmark
ID: 17807527
No CDate() doesnt work.
0
 
LVL 4

Expert Comment

by:Xeavn
ID: 17807759
What exactly is being passed to it? In other words what is the value of your string at this point?
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:rowmark
ID: 17808119
25/10/2006
0
 
LVL 6

Expert Comment

by:Roopesh_7
ID: 17808494
datetime dt ;

if(task.DateTime != null)
     dt =  Convert.ToDateTime(task.DateTime);
else
      dt = datetime.\\; give defult value = 01/01/1900

then pass dt to function

             
0
 

Author Comment

by:rowmark
ID: 17808654
nope this doesnt work as my database date format is  mm/dd/yyyy

0
 
LVL 12

Accepted Solution

by:
sandip132 earned 500 total points
ID: 17809008
TRY THIS...C# Code

System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");  // Set your required format culture
DateTime a = DateTime.Parse(task.DateTime,culture,System.Globalization.DateTimeStyles.NoCurrentDateDefault);

Regards,
Sandip.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question