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

  • Home
  • SEARCH
  • 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 657211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:47:55+00:00 2026-05-13T22:47:55+00:00

Why would dateTimePicker.Value.Date.ToShortDateString(); act differently on Windows 7 x64 PL, Windows Vista x32 PL

  • 0

Why would dateTimePicker.Value.Date.ToShortDateString(); act differently on Windows 7 x64 PL, Windows Vista x32 PL and Windows XP PL with to my knowledge exact regional settings. I’ve found it out the hard way that i was doing this conversion prior to entering it to DB.

It was working fine on Windows 7 (my development machine), colleague VISTA system but it failed to work on Windows XP (day was switched with month all the time). Also on higher systems we have 2010-01-13 displayed on ListView while on his system he has 13-01-2010.

I imagine in my old code i may have more of those type conversions and i will have to go thru and verify it but i would like to know why it’s behaving that way on same regional settings. I imagine I should never do conversions like that but I’ve learn it the hard way after a long time when it was working fine.

EDIT:

I was using it this way (commented out code that was causing troubles). Back in the old days I thought ToShortDateString was the only way to make sure to put it into DB without Time (since i was reading DateTimePicker). I know now that I should have used .Date on that DateTimePicker but I am smarter now that it did blow up on me. Here’s the code:

    private static void sqlWpiszDaneSwieta(DateTime varData, string varDataNazwa) {
        //string varDataSwieto = varData.ToShortDateString();
        const string preparedCommand = @"INSERT INTO [dbo].[TypyDatySwiat]
                                           ([SwietaData]
                                           ,[SwietaNazwa])
                                     VALUES
                                           (@varData
                                           ,@varDataNazwa)";
          using (var varConnection = Locale.sqlConnectOneTime(Locale.sqlDataConnectionDetails))
        using (SqlCommand sqlWrite = new SqlCommand(preparedCommand, varConnection)) {
            sqlWrite.Prepare();
            sqlWrite.Parameters.AddWithValue("@varData", varData);
            sqlWrite.Parameters.AddWithValue("@varDataNazwa", varDataNazwa);
            try {
                sqlWrite.ExecuteNonQuery();
            } catch (SqlException sqlEx) {
                if (sqlEx.Message.Contains("Violation of PRIMARY KEY constraint")) {
                    MessageBox.Show("Dodanie podanego święta jest niemożliwe. Podane święto istnieje już w bazie danych!", "Bład", MessageBoxButtons.OK, MessageBoxIcon.Error);
                } else {
                    MessageBox.Show(sqlEx.ToString(), "Bład SQL", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            } catch (Exception ex) {
                MessageBox.Show(ex.ToString(), "Bład", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

So i am not specifically asking for a way to do it. I know how to do it and that i can pass it using DateTime directly to db. Just that i would like to know why would it behave differently on 1 machine.

  • 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-13T22:47:55+00:00Added an answer on May 13, 2026 at 10:47 pm

    day was switched with month all the time

    That sounds suspiciously like your colleague is using a UK locale on his XP machine, as that is the normal method for a date there.

    But I’m more concerned about this:

    prior to entering it to DB.

    If you’re putting it into a DB, why are you calling .ToShortDateString()? That smells like dynamic sql to me, and that means an sql injection vulnerability. Instead of something like this:

    string sql = "INSERT INTO [MyTable] (MyDateColumn) VALUES (" + MyDateVar.ToShortDateString() + ")";
    //sql command/connection code omitted from this sample
    

    you need to do something like this:

    string sql = "INSERT INTO [MyTable] (MyDateColumn) VALUES (@MyDate)"
    using (var cn = new SqlConnection("..connection string.."))
    using (var cmd = new SqlCommand(sql, cn))
    {
        cmd.Parameters.Add("@MyDate", SqlDbType.DateTime).Value = MydateVar;
    
    //remain code omitted
    

    Notice the latter sample never converts the datetime variable to a string. It will work no matter what locale your users have set.

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

Sidebar

Related Questions

Im using a JQuery Datepicker (datetimepicker actually) and would like the date (and time)
I would like to be able to display a DateTimePicker that has a default
When you add a DateTimePicker control, you can select part of the control value
I have a simple form, with two DateTimePicker-controls: One for date, and one for
I've run into a very specific bug with the DateTimePicker control in Windows Forms.
I stored a date value and retrieve it and the format of the date
If you use a .NET DateTimePicker with the maximum date set to an earlier
Would it not make sense to support a set of languages (Java, Python, Ruby,
Would it be possible to print Hello twice using single condition ? if condition
Would it be possible to show an image in full screen mode using silverlight.

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.