Jump to content

how to retrieve only date from datetime from database


arpitsharma

Recommended Posts

i have a form in which i have a field date of birth , and a textbox to fill date of birth , when a person fills his date of birth like 01/01/1990 , then it will be saved into database , and when i retrieve this date form database then this comes 01/01/1990 12:00 AM , i want only date part from it.

This is my form to fillup date of birth

form.aspx

 <tr>
      <td width="30%">
         Date of Birth
          <br />
      </td>   <td style="width: 1px">
       :<asp:TextBox ID="txtDateofBirth" runat="server" placeholder="dd/mm/yyyy"></asp:TextBox>
       </td> <td class="td2">                                                                                     
                                                                 
                                                                                               
          </td>
          </tr>

this is code for form.aspx.cs

 SqlCommand cmd = new SqlCommand("insert into ApplicantForm(NameofApplicant,  dateofbirth)" +
                                                                "values( @NameofApplicant, convert(Datetime, @dateofBirth, 103)", con);
cmd.Parameters.AddWithValue("@dateofBirth",txtDateofBirth.Text);

this is code for print of this date of birth

print.aspx

   <asp:Label ID="txtDOB" runat="server"  ></asp:Label>

this is code print.aspx.cs

  SqlCommand cmd = new SqlCommand("Select * from ApplicantForm Where ApplicantId=" + ((Request.QueryString["ApplicantId"])) + "", con);
 dr = cmd.ExecuteReader();
 
txtDOB.Text = dr["dob"].ToString();

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...