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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:03:51+00:00 2026-06-16T00:03:51+00:00

I unable to convert string to date, my string like 17/12/2012 Code written for

  • 0

I unable to convert string to date, my string like 17/12/2012
Code written for this is shown below

public string Date_Convert(string dt1)
{
    string strdate = string.Empty;
    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
    DateTime dt = Convert.ToDateTime(dt1);
    strdate = dt.Month.ToString() + "/" + dt.Day.ToString() + "/" + dt.Year.ToString();
    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
    return strdate;
}

It is working fine in my local system. And not working in my server(which is located at Australia)of course I tried with different culture settings in the above code,

I’m using this date string in sql query in where condition.

please help me, It killed my one day time, and thanks in advance.

  • 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-16T00:03:52+00:00Added an answer on June 16, 2026 at 12:03 am

    Instead of switching the culture, why don’t you do something like this:

    public string Date_Convert(string dt1)
    {
        DateTime dt = DateTime.ParseExact(dt1, "dd/MM/yyyy", new CultureInfo("en-GB"));
        return dt.ToString("d", new CultureInfo("en-US"));
    }
    

    Also: If you use the value in an SQL query (and provided that your query works on a DATETIME field, not NVARCHAR), you should also consider using a parameterized query to pass the DateTime value to the database to avoid SQL injection.

    For example:

    DateTime value = DateTime.Parse(dt1, new CultureInfo("en-GB"));
    using (SqlCommand cmd = new SqlCommand("SELECT ... FROM ... WHERE Date = @date", connection))
    {
        cmd.Parameters.AddWithValue("@date", value);
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below code to convert a string to the type T. It
I am unable to covert String values in The Java.util Date format. This is
I am unable to convert strings to date with throwing exceptions of not proper
I am unable to convert JSON string to .net object in asp.net. I am
I have a code snippet in C# but unable to convert to VB.NET. I
i have the code in c# string date = reader[date].ToString(); and got error that
I'm getting following error when invoking my testtag.jsp : org.apache.jasper.JasperException: Unable to convert string
I am getting the Unable to convert MySQL date/time value to System.DateTime error because
I am trying to convert a string into Date using Derived column and I
Possible Duplicate: convert string to nsdate The NSString has following value '2012-07-11T15:59:16' 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.