locked
Date Format match between client and server RRS feed

  • Question

  • Am posting an object from client to server via AJAX in ASP Net which consist of date Property too.MY Machine's time zone uses the date format **MM/dd/yyyy** in string whereas my server time zone uses the format **dd/MM/yyyy**.Am still wondering that how do the conversion takes place properly and it works as expected result which gets saved in the database.
    Say for example am posting a value from client 02/01/2016(MM/dd/yyyy) in string which gets changed properly in server to 01/02/2016(dd/MM/yyyy). How do they know that the incoming value was in (MM/dd/yyyy) and then parses to (dd/MM/yyyy).
    Let me know if i was wrong/misunderstood.
    • Moved by Kristin Xie Wednesday, February 3, 2016 7:42 AM
    Tuesday, February 2, 2016 6:45 AM

All replies

  • Please post asp.net questions under asp.net forums

    Fouad Roumieh

    Tuesday, February 2, 2016 6:59 AM
  • Hi,

    The language used was C#. So I just posted the question here.

    Regards,

    Selvam.M

    Tuesday, February 2, 2016 7:20 AM
  • Hi,

    The language used was C#. So I just posted the question here.

    Regards,

    Selvam.M

    C# is used in asp.net, in asp.net they can be reading culture used with the HTTPRequest vars and other things that can be explained there not here. 

    Fouad Roumieh

    Tuesday, February 2, 2016 7:32 AM
  • In general terms, whatever a user inputs into a textbox on his client machine this will be interpreted according to the current culture of that client machine.

    Assuming that everything is correctly coded, that input will then be stored in a DateTime type variable. The DateTime type is independent of culture; it just represents a date. How this is stored internally is irrelevant but just think of it as a structure with Day, Month and Year properties (plus the time-related properties), so how these are represented as text doesn't matter.

    Hopefully, the rest of your code simply maintains this information as a DateTime rather than a text string. Even if this information has to be transferred across boundaries, i.e. from a client to a server machine, as long as it is kept in a DateTime variable and not converted to a string anywhere, then this is just fine. It will still have the same value on the server and will saved to the database correctly.

    Ultimately, culture and whether a datetime is represented as d/m/y or m/d/y only matters when a DateTime must be displayed on a screen or read from a screen and therefore converted to or from a string.


    • Edited by RJP1973 Tuesday, February 2, 2016 9:29 AM
    Tuesday, February 2, 2016 9:29 AM
  • Hi,

    Thanks for the info. Read some of the articles about how ASP Net MVC via Model Binding. Able to get some knowledge on those. Found some cases where conversion took place wrongly which was in the case when client and server are in same formats .

    Say for example when client and server are in the format M/d/yy and server confirms that the incoming date was in the format of d/M/yy and then parses wrongly placing month in the place of date and date in the place of month.

    Regards,

    Selvam.M

    Tuesday, February 2, 2016 10:35 AM
  • There is no general date format on a webpage and you can not standard find the date format (culture) the end user is using. (Which is possible with Windows solutions).

    Therefore you have to tell the end user exactly how to type the date as you want (clear what is the day, month and year and how many positions). 

    Modern database uses no string values for dates. Microsoft database servers use a binary value based on ticks (100th nanoseconds) which starts on a certain date.  

    For more on a webpage based answer use the Microsoft ASP.Net forums mentioned by Fouad.


    Success
    Cor



    • Edited by Cor Ligthert Tuesday, February 2, 2016 11:49 AM
    • Proposed as answer by Kristin Xie Wednesday, February 3, 2016 7:42 AM
    Tuesday, February 2, 2016 11:47 AM
  • Hi,

    Thanks for the info. Read some of the articles about how ASP Net MVC via Model Binding. Able to get some knowledge on those. Found some cases where conversion took place wrongly which was in the case when client and server are in same formats .

    Say for example when client and server are in the format M/d/yy and server confirms that the incoming date was in the format of d/M/yy and then parses wrongly placing month in the place of date and date in the place of month.

    Regards,

    Selvam.M

    You are posting to the wrong forum for an answer.

    http://forums.asp.net/1146.aspx/1?MVC

    Wednesday, February 3, 2016 4:00 AM