-1
public JsonResult TimeValidation(string pickUp, string delivery)   
{

    var errorMessage = string.Empty;
    var dateTime = DateTime.MinValue;

    if (!DateTime.TryParse(pickUp, out dateTime))
        errorMessage = "Invalid date";

     if (!DateTime.TryParse(delivery, out dateTime))
        errorMessage = "Invalid date";
}
‎4‎/‎29‎/‎2015‎ ‎3‎:‎30‎:‎00‎ ‎PM pickup from ie
4‎/‎30‎/‎2015‎ ‎12‎:‎00‎:‎00‎ ‎AM delivery from ie
4/29/2015, 3:30:00 PM pickup from  firefox
4/30/2015, 12:00:00 AM delivery from firefox  

its working good in chrome and firefox but its not converting to datetime in internet explorer 11 please obseve , between date and time

  • 7
    C# doesn't run in the browser. Can you explain a bit more what exactly you're doing? – Cameron Apr 28 '15 at 16:39
  • 1
    *What* is being converted to a `DateTime` in IE? – Rufus L Apr 28 '15 at 16:40
  • Are you getting the `stringDate` value from the browser? If so, you should show how you obtain it. – Matt Johnson-Pint Apr 28 '15 at 16:41
  • @Rufus L string date should be converted into datetime ... – Sreeranga Prasad Apr 28 '15 at 16:42
  • @Juan C it is not converting to datetime it returns false in my if condition please observe ! in if condition – Sreeranga Prasad Apr 28 '15 at 16:44
  • Ok, cool. The wording changed since I commented. But this is C#, not browser code. Something else must be going on when you're passing it to java or asp.net. Also, you're missing a semi-colon after the string assignment. – Rufus L Apr 28 '15 at 16:47
  • Edit your question and add the portion of code where `stringDate` comes from. – zed Apr 28 '15 at 16:50
  • Add the code of the browser from where you atually send the date `pickUp` – zed Apr 28 '15 at 16:57
  • You still did *not* show where `pickup` and `delivery` are coming from. You need to provide a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). We shouldn't need to prompt you for these details - when you ask a question, make sure you've given a *complete* example. – mason Apr 28 '15 at 16:58
  • @mason i updated my code. if i am right problem is comma symbol , in between date and time – Sreeranga Prasad Apr 29 '15 at 08:43
  • So remove the comma? Or use client side validation to make sure that the data sent to the server is correct? Or use a different function to parse the date on the server, or try to parse several formats? Anyways, you shouldn't be accepting the dates as strings. You should use the `DateTime` type and let the framework convert it for you. – mason Apr 29 '15 at 13:02
  • @Cameron pickUp string is converted some other format like this **4?/?30?/?2015? ?9?:?30?:?00? ?PM** – Sreeranga Prasad Apr 30 '15 at 15:21
  • I have also catched this issue and it only reproduces if request comes from IE11 and culture is set to es-PE. Date example - Mon, 07 Mar 2016 10:09:34 GMT. CurrentCulture and CurrentUICulture has same values and all params similar to culture settings that assigned in case if request come from Firefox or Chrome. Also, in my case, used basic or windows authorization of users from AD and I think it somehow related! – Maxim Nikonov Mar 25 '16 at 13:04

2 Answers2

1

Assuming this is C# (looks like it is) and it is running on the server (not actually in the browser): You should check to see what the value of System.Globalization.CultureInfo.CurrentCulture is. See if it is different for a request coming from IE vs one of your other browsers. DateTime.TryParse(string, out DateTime) uses this value to help parse the string.

For instance, the date you provided: "28/04/2015 07:59:00" will cause TryParse to return false if the current culture is en-US, but if the current culture is es-MX, then it will return true.

I'm not sure why it would be different between browsers off the top of my head, but it's at least a place to start looking.

Brian Ball
  • 12,268
  • 3
  • 40
  • 51
0

I came across a similar issue and the issue was the javaScript method toLocaleDateString() in IE11 return string with some RTL characters! which results in invalid data and these characters aren't visible.

A simple fix using regex

toLocaleDateString().replace(/[^A-Za-z 0-9 \.,\?""!@#\$%\^&\*\(\)-_=\+;:<>\/\\\|\}\{\[\]`~]*/g, '')

I tried the same regex at the back C# but it didn't work, however, I didn't want to spend more time on this so I just applied the front end solution.

More details, source

et3rnal
  • 322
  • 4
  • 17