Will the SQL Server default dateformat/language affect my DateTime object toString rendering?

Is there any relation between the SQL Server default date format/language and a DateTime object rendered as a String in a asp.net application?

Can the default SqlServer date format affect the DateTime strings from my reports I generated? The asp.net application is using EntityFramework to get data.

  • Update values in identity column
  • Query to find all FK constraints and their delete rules (SQL Server)
  • SSDT Change Tracking
  • Enumerated types in SQL Server 2008?
  • SQL Server Script to create a new user
  • sql login failed for user X…windows authentication only
  • Dynamic multi-database Context with Entity framework
  • GUID not being generated automatically when db.submitchanges()
  • gridview is not showing Data
  • How to check case sensitive password in sql server08
  • The DELETE statement conflicted with the REFERENCE
  • SQL update command with unique constraint asp.net
  • 2 Solutions collect form web for “Will the SQL Server default dateformat/language affect my DateTime object toString rendering?”

    SQL Server stores datetime type as binary. It uses 8 bytes. First 4 byte is for the date and second 4 byte is for the time.

    This type is mapped with System.DateTime in CLR side and this System.DateTime does not have format either. It just have date and time values. It is based on Ticks wihch is the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 in the Gregorian calendar.

    As you can see, both are actually kind of numeric values.

    On the other hand, the “format” concept only applies when you get their textual (aka string) representations which is usually done with DateTime.ToString method in C# side and Format method in SQL Server side.

    So, if you choose right data type (see: Bad habits to kick : choosing the wrong data type) for your System.DateTime values in your SQL Server (usually done with datetime or datetime2), no, your SQL Server default date format/language does not affect the format that generated for your reports.

    When you feed your reports directly with your DateTime value, the ToString() method will called automatically (if there is no custom format etc..) and this method uses standard The "G" Format Specifier with your CurrentCulture settings.

    For beginners, it is really important to understand the difference between a DateTime instance and their string representations (format).

    Quoting MSDN:

    DateTime toString method converts the value of the current DateTime
    object to its equivalent string representation using the specified
    format and the formatting conventions of the current culture.

    Which means, no it will not. Rendering will be affected by application culture setting – so however you will handle it it will show date time accordingly.

    Current culture (as on MSDN again)

    The culture is a property of the executing thread. This read-only
    property is equivalent to retrieving the CultureInfo object returned
    by the Thread.CurrentCulture property. When a thread is started, its
    culture is initially determined by calling the Windows
    GetUserDefaultLocaleName function.

    In case of ASP.NET most likely this would be a setting derived from user’s operating system culture setting (I took long shortcut here). However this might be overridden in web.config (or elsewhere):

    <globalization uiCulture="en" culture="en-US" />
    
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.