Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem parsing DateTime

Posted on 2008-10-14
7
Medium Priority
?
1,037 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 1500 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

730 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