Solved

Problem parsing DateTime

Posted on 2008-10-14
7
1,024 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
[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
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…

710 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