locked
asp net display date from database without time RRS feed

  • Question

  • User-775536502 posted

    hii evryone 

    i am tray to display date from database to lable without the time 

    i have colum "Date" in my database and i want to display the value without the time 

    the code is

    int id = 2;
        protected void Page_Load(object sender, EventArgs e)
        {
            con.Open();
            SqlCommand cmd = new SqlCommand("select * from [Order] where Id = '" + id + "'", con);
            SqlDataReader rd = cmd.ExecuteReader();
            if (rd.Read())
            {
                lblDate.Text = rd["Date"].ToString();
                
                txtDate.Text = rd["Date"].ToString();
    
            }
            rd.Close();
            con.Close();
        }

    in the lable its show this value "09/11/2017 00:00:00

    how can i display jast the date ?

    Wednesday, November 1, 2017 5:59 AM

All replies

  • User-1838255255 posted

    Hi barakkadosh,

    According to your description, about how to show date of datetime, please check the following sample code:

    Sample Code:

    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Label ID="lblDate1" runat="server" Text=""></asp:Label>
            <asp:Label ID="lblDate2" runat="server" Text=""></asp:Label>
        </div>
        </form>
    </body>
    
    
    protected void Page_Load(object sender, EventArgs e)
            {
                //suppose this is from your database
                DateTime dateAndTime = DateTime.Now;
                lblDate1.Text = dateAndTime.ToShortDateString();
    
                //or for string type
                var date = DateTime.Now.ToString();
                var newdate = new string[] { };
                newdate = date.Split(' ');
                lblDate2.Text = newdate[0];
            }

    Best Regards,

    Eric Du

    Wednesday, November 1, 2017 9:44 AM