Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7531777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:15:52+00:00 2026-05-30T05:15:52+00:00

The format of DateTime.UtcNow.ToString() is – DD/MM/YYYY HH:MM:SS The format that SQL Server Express

  • 0

The format of DateTime.UtcNow.ToString() is – DD/MM/YYYY HH:MM:SS

The format that SQL Server Express expects is – YYYY/MM/DD HH:MM:SS

The format of (SqlDateTime)DateTime.UtcNow is – DD/MM/YYYY HH:MM:SS

As far as I know both are UK formats. I am in the UK and running the code and SQL Server Express on the same machine.

I know I could specify the format in the ToString() method but that doesn’t answer the underlying problem. Why does SQL Server Express expect a different format when it is running on the same machine?

What is the best way to resolve this mismatch so that it also works when I publish to the server (which might not have this problem)?

Should I synchronize the date formats on my machine and assume things will be fine when I publish? If so how do I do this? Or should I handle it in code by somehow detecting the date format of SQL Server Express and making my code produce the same format? If so how do I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:15:53+00:00Added an answer on May 30, 2026 at 5:15 am

    Use a standard, unambiguous, language- and regional settings-neutral format. If you must use a string, pass in the following format (which I know you can achieve in .NET with .ToString()):

    YYYY-MM-DDTHH:MM:SS
    

    For example:

    Console.WriteLine(DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss"));
    

    The reason this is preferable is that it won’t matter where your code runs, what changes are made to the underlying operating system, or what changes are made on the SQL Server side, the date will always be correct and will not be misinterpreted. With the above format, you will never have to worry if it is misinterpreted for any of the wide variety of reasons this could happen (session settings like LANGUAGE and DATEFORMAT, regional settings, locale, even your own code can make assumptions about the incoming string format). There are only a couple of truly safe formats for SQL Server, and mm/dd/yyyy and dd/mm/yyyy are absolutely not among them.

    Now, I am not sure why you are using a string in the first place. Best practice suggests that you should be passing a datetime parameter from C#, not a string literal. There is no reason to convert it to a string. A lot of folks will let users enter dates manually into a textbox, and just pass what they enter. Don’t do this – force them to pick from a calendar control or set of dropdowns, and construct a datetime value from that. If you let users enter dates, you can never be sure if one person’s 09/07/2013 is, in fact, another person’s 07/09/2013.

    All that said, if you just want to enter the current time, it can be much less problematic to just let SQL Server provide the value, since it has this ability too. So for example if you are storing this data in a column for a new row you are inserting, set up the column as:

    ModifiedDate DATETIME NOT NULL DEFAULT GETUTCDATE()
    

    Now you don’t have to pass this parameter from .NET or even mention the column name in your INSERT statement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<abbr class=timeago title='<%= DateTime.UtcNow.ToString(yyyy-MM-ddTHH:mm:ssZ) %>'><%= String.Format({0:MMMM d, yyyy}, DateTime.Now) %></abbr> + $(document).ready(function () {
I need an expression which matches,DateTime format (DD/MM/YYYY),i've already found it. However,it only works
SQLite docs specifies that the preferred format for storing datetime values in the DB
I have problem with datetime format for C# and T-SQL. C# application is using
Possible Duplicate: Mysql: Setup the format of DATETIME to 'DD-MM-YYYY HH:MM:SS' when creating a
The javadoc for org.joda.time.format.ISODateTimeFormat.dateTime() is: Returns a formatter that combines a full date and
Is there any way I can get datetime format like ' YYYY-MM-DD HH:MM:SS '
I have Entity class with datetime filed, I want to select distinct 'mon-yyyy' format
currTime = DateTime.Now.ToString(u); The code above first formats the time now to yyyy-mm-dd hh-mm-ss
i want to parse any datetime format to dd/MM/yyyy format. here is my code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.