Solved

Problem parsing DateTime

Posted on 2008-10-14
7
1,013 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

18 Experts available now in Live!

Get 1:1 Help Now