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
Solved

Problem parsing DateTime

Posted on 2008-10-14
7
1,021 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
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.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

837 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