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.

  • How to measure table size in GB in a table in SQL
  • Update listbox on time asp.net
  • Selecting max record for each user
  • Insert into replicated table fails - identity range check
  • Compressing a text field in Sql Server 2k8 R2
  • Simple Query to Grab Max Value for each ID
  • Authentication in SSIS SMTP Connection Manager?
  • Error: String or binary data would be truncated. The statement has been terminated
  • Display varbinary as a downloadable link
  • Retrieving Return value from stored procedure
  • Select Query with Where condition depending on list values in asp.net
  • Connecting to database for Multi-Tenant application?
  • 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.