Solved

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

Posted on 2006-10-25
7
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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 use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

738 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