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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:55:13+00:00 2026-06-14T19:55:13+00:00

I have a SQL Server database which has a column of date with value

  • 0

I have a SQL Server database which has a column of date with value of 2001-12-23. The insert statement makes sure that the input is correctly formatted using the following code:

var start_date_formatted = DateTime.ParseExact(start_date.Text, "dd-MM-yyyy", null);

Even though the input is formatted as dd-MM-yyyy it still appears in the database as 2001-12-23.

The thing that I don’t understand is the fact that whenever I query the data from the database, it returns the date correctly formatted dd-MM-yyyy even though it appears in the database as yyyy-MM-dd.

That is not a big deal since I got the formatting I need eventually.

The problem is that the time string is being added to my date generating the output of 23-12-2001 00:00:00. I need date only but can’t figure out why is it being added and why can’t I change it using the following method:

DateTime.ParseExact(startdate, "dd-MM-YYYY", null); // string is not recognized as valid DateTime

or

.ToString("dd-MM-YYYY"); // no overload method ToString that takes 1 argument

Since I’m new to asp.net I would like to get to know how to handle date formats and if there is any general config setting which would require and set certain date format?

UPDATE

var dt = BookingAccess.ManageBookingsDataTable();
            string id = string.Empty;
            string name = string.Empty;
            string startdate = string.Empty;
            string enddate = string.Empty;
            string full_string = string.Empty;
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    id = dt.Rows[i]["id"].ToString();
                    var sdate = dt.Rows[i]["start_date"];
                    name = dt.Rows[i]["Pet name"].ToString();
                    startdate = dt.Rows[i]["start_date"].ToString("dd-MM-yyyy"); // error is thrown here
                    enddate = dt.Rows[i]["end_date"].ToString();
                    full_string = startdate + " to " + enddate + " (" + name + ")";
                    CurrentBookings.Items.Add(new ListItem(full_string, id));
                }
            }

This does not seem to format the date either:

startdate = string.Format("{0:dd/MM/yyyy}", dt.Rows[i]["start_date"].ToString());
  • 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-14T19:55:14+00:00Added an answer on June 14, 2026 at 7:55 pm

    In C# there is no Type Date, so all dates is variables of DateTime type. So when you get date from db it transfers into DateTime variable with time 00:00:00

    To get string from this you can use ToString("dd-MM-yyyy"):

    var dt = DateTime.Now;
    string dateinstring = dt.ToString("dd-MM-yyyy")); //it contains "23-11-2012"
    

    Update:

    Your problem is that your datatable is not typed, so your startdate is object, not DateTime. You should cast it to DateTime:

    startdate = ((DateTime)dt.Rows[i]["start_date"]).ToString("dd-MM-yyyy");
    

    This will works if your dt.Rows[i]["start_date"] is not nullable, in other case you should check that it is not null before casting.

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

Sidebar

Related Questions

I have a database (SQL server express 2008) which has a column that is
In sql server database, I have column name Image which has urls like http://www.xyz.com/1009/image1.jpg
I have a SQL Server database which has grown to more than 15GB in
I have a column type money in my sql server database, which is moneyAcumulated
I have a SQL Server database with an Apartment table (which has columns FloorNum
I have a table in my SQL Server database called items which has a
I have a SQL database table column which has data in this format 0000-00-0000
I have one SQL server database which was created using Import/Export Wizard from an
I have a SQL Server database which is shared between several ASP.NET (VB.NET) websites,
I have a SQL Server database which I can read from, is there a

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.