Click here to Skip to main content
15,923,006 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i Choose Short Date Format in Database , And i Insert Short Date to DataBase From Form , but When i Read Data , its Long Date Format.

Example : i insert "1390/12/12" to DataBase But It Save "AM 12:53:00 1390/12/12"

Note: my Date Field Format in My DataBase is : Short Date
Posted
Comments
Sander Rossel 12-Nov-11 10:26am    
Perhaps you should also mention you are using a solar calendar.

1 solution

Short date is only the presentation of the data. Not how it is stored.
If you want to store only the date portion of your datetime in VB use DateTime.Date (instead of DateTime.Now or the default value).
For example:
VB
Dim dt As Date = DateTime.Now ' dt will now store date AND time, regardless of the date type.
dt = dt.Date ' dt will now be the same date, but it's time value is set to 00:00.

In Access it seems you have to use the DateValue Function.
See here[^] for more details.
Hope that helps :)
 
Share this answer
 
Comments
synctor 12-Nov-11 12:09pm    
its not working !

Dim dtt as Date
dtt= txt_date_birth.text
...
com.Parameters.AddWithValue("date_birth", dtt.date)
Sander Rossel 12-Nov-11 12:59pm    
Try putting option Strict on. This can be done in your project settings under the compile tab.
txt_date_birth.Text is a String.
You cannot simply assign a String to a Date. You will have to check if the String is in a correct Format and convert/parse it.
You can use the DateTime.TryParse Method. http://msdn.microsoft.com/en-us/library/ch92fbc1.aspx
Also make sure your query is correct and actually returns any values.

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