Solved

Problem parsing DateTime

Posted on 2008-10-14
7
1,014 Views
Last Modified: 2010-05-18
Hi All,

I am facing a problem with DateTime in a web project.. (ASP.Net 3.5)

I didnt have any problem when i was running the application on the development machine.
But when i deployed on IIS 6.0 it started throwing errors.

To be more specific; when i put in a date 12/10/2008 it works, but i put in 13/10/2008 it doesnt.
From this i can guess Month and Day element are displacing somewhere.

The following is something similar to what i am doing with the datetime

String strSQlDateTime= SqlDateTime.Parse(myObject.MyStartDate.ToString()).ToString()

myObject is a an object of a Custom class.
myObject.MyStartDate is of DateTime

I have already assigned myObject.MyStartDat = DateTime.Parse(textBoc.Text);
I am pretty sure there is no problem up to this point.

But when i try to parse the datetime with SqlDateTime it seems to be throwing an exception..

This is the description of the Exception
Exception Details: System.FormatException: String was not recognized as a valid DateTime.


Detail is as follows
System.Web.HttpException: Error executing child request for ViewReport.aspx. ---> System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.FormatException: String was not recognized as a valid DateTime.
   at System.DateTimeParse.ParseExactMultiple(String s, String[] formats, DateTimeFormatInfo dtfi, DateTimeStyles style)
   at System.DateTime.ParseExact(String s, String[] formats, IFormatProvider provider, DateTimeStyles style)
   at System.Data.SqlTypes.SqlDateTime.Parse(String s)
   at Reports_Revenue_ViewReport.getSQLQuery(AdvSearchCriteria c) in c:\Inetpub\wwwroot\Telecafe Reporting\Reports\Revenue\ViewReport.aspx.cs:line 90
   at Reports_Revenue_ViewReport.bindData() in c:\Inetpub\wwwroot\Telecafe Reporting\Reports\Revenue\ViewReport.aspx.cs:line 120
   at Reports_Revenue_ViewReport.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\Telecafe Reporting\Reports\Revenue\ViewReport.aspx.cs:line 35
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   --- End of inner exception stack trace ---
   at System.Web.UI.Page.HandleError(Exception e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   at System.Web.UI.Page.ProcessRequest()
   at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
   at System.Web.UI.Page.ProcessRequest(HttpContext context)
   at ASP.reports_revenue_viewreport_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\fadda1cd\316ac73d\App_Web_jezxdfxc.2.cs:line 0
   at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)
   --- End of inner exception stack trace ---
   a
0
Comment
Question by:justin_smith
  • 3
  • 3
7 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 22718166
That is because the default format for date in sql will be mm/dd/yyyy.

So that will throw an error if u are entering 13/10/2008

13 can't be a month... Try using cultures
0
 

Author Comment

by:justin_smith
ID: 22718226
Could you please explain how i could use cultures in this instance..

And what could be the reason for the app to run fine on the dev machine and crash on the IIS


Thanks
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 22719142
Its the regional settings that are causing the problem. The app is working fine on the dev machine because the regional settings are dd/mm/yyyy for the date. But on the server the regional settings are probably mm/dd/yyyy so 13 as the month is generating error.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:justin_smith
ID: 22720234
I doubted the same but the regional settings are identical in both machines unless there something specific to IIS is happening
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 22720490
It could be something specific to IIS but is more likely to be specific to SQL Server. Can you not use the standard datetime.parse instead of sqldatetime.parse?
0
 

Author Comment

by:justin_smith
ID: 22725577
Well. CodeCruiser, thats what i am doing with string format of the datetime
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 22726433
I did not understand what you mean here.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

930 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now