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 8113007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:41:19+00:00 2026-06-06T02:41:19+00:00

I want to convert a string ’30/12/2012′ to ‘2012/12/30’. My application is set to

  • 0

I want to convert a string ’30/12/2012′ to ‘2012/12/30’. My application is set to “en-CA” however the database accepts yyyy/MM/dd as default.

How can I do this without depending on the current culture info set
at server?

  • 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-06-06T02:41:21+00:00Added an answer on June 6, 2026 at 2:41 am

    As all the comments have said, but none of the answers have said so far: don’t pass this to the database as a string.

    Parse any text you receive as early as possible, then use DateTime to represent it everywhere else, including how you send it to the database, via parameterized SQL1. This goes for values of all kinds: convert it into the “natural” type for the data as soon as possible, and keep it in that natural representation for as long as possible. A date isn’t a string, and you should only convert it to a string if you really, really need to – ideally just before displaying it to a user.

    The parsing can be done with DateTime.ParseExact or DateTime.TryParseExact depending on whether this is “suspicious” data (e.g. from a user) or data which should really be correct and for which an exception is the most appropriate reaction to unparseable values. I suggest you pass in CultureInfo.InvariantCulture with your custom format string. For example:

    DateTime date = DateTime.ParseExact(text, "dd/MM/yyyy",
                                        CultureInfo.InvariantCulture);
    

    (If you do a lot of date/time work, you may also want to consider using my Noda Time project which allows you to express the value in a richer way – in this case you’d probably use LocalDate.)


    1 If you’re not already using parameterized SQL, but are instead baking values directly into the SQL, you have bigger problems than date/time conversions.

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

Sidebar

Related Questions

I want to convert a string to formatted text in C# in WPF application,
I want to convert a string like 2012-03-08T00:00:00+01:00 into Date.. I tried to use
In my c# application i want to convert a string characters to special characters.
I want to convert a string to HTML entities/special characters so that I can
I want to convert a string to XML. Of course I can do something
I want to build a method that can convert a String value to a
I want to convert following string into NSDate format 2012-04-29T08:20:04Z Please help me. How
i want to convert a string variable which has the value in mm-dd-yyyy hh:mm:ss
I want to convert string Thu, Nov 22, 2012 to NSDate . I've tried
I want to convert String to Date in different formats. For example, I am

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.