Click here to Skip to main content
15,909,747 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Well I'm trying to add only date when some data inserted into database without datetimepicker1.

Everything seems fine till the default time showing along with date.

Is there anyways to get rid of that time showing in database ?

What I have tried:

Private Sub Submit_Click(sender As Object, e As EventArgs) Handles Submit.Click
Dim todayDate As Date = Date.Now.ToString(" yyyy-MM-dd ")
Dim command As New SqlCommand("INSERT into EmployeeDetails(AddedOn)Values(@AddedOn)")
command.Parameters.Add("@AddedOn", SqlDbType.VarChar).Value = getDate
End Sub
Posted
Updated 23-Feb-18 10:53am

1 solution

VB.NET
Dim command As New SqlCommand("INSERT into EmployeeDetails(AddedOn)Values(@AddedOn)")
command.Parameters.AddWithValue("@AddedOn", Date.Today)

NB: If your column type is defined as datetime or datetime2, this will store the date with a time of 00:00:00. If you want to store the date without any time information, then change your column type to date.

Date and time types | Microsoft Docs[^]
 
Share this answer
 
Comments
Maciej Los 24-Feb-18 4:08am    
5ed!
Babai JermenKeller Sasmal 24-Feb-18 8:27am    
Works like charm. Ty EXPERT

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900