Click here to Skip to main content
15,906,626 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
what changes i do in update command for Date format ?

What I have tried:

i am using
Val(TextBox2.Text)
'textbox2 contains date
Posted
Updated 22-Nov-17 0:13am
v4
Comments
ZurdoDev 21-Nov-17 8:51am    
The way you display a date has nothing to do with the way you save it in the db. As I recall, Access wants #'s around the date. Post the code that is causing an error and what the error is. Otherwise, there isn't enough here to help you.

There is no such thing as a "format" for a DateTime value in a database. The format is applied when the date is displayed, and you have control over that.

If you're saving dates as text in your database, you're most assuredly doing it wrong. NEVER save DateTime values as text. Always use the proper date type for your data.
 
Share this answer
 
For everything that is related to parsing a string to a value (integers, reals, dates, etc...), you should always use the TryParse method of the target valuetype.
In your example, that would be:
VB.NET
Dim myDate As DateTime
If (DateTime.TryParse(TextBox2.Text, myDate))
   '' DateTime correct format
Else
   '' DateTime incorrect format
End If

The TryParseExact method gives you even more control on the input format.
DateTime.TryParse Method[^]
DateTime.TryParseExact Method[^]
 
Share this answer
 
Comments
shiwajee 21-Nov-17 12:16pm    
Dim myDate As DateTime
If (DateTime.TryParse(TextBox2.Text, myDate)) Then
'' DateTime correct format
TextBox2.Text = FormatDateTime(TextBox2.Text, DateFormat.ShortDate)
End If
Solution not working yet
Richard Deeming 22-Nov-17 10:59am    
Dim myDate As DateTime
If DateTime.TryParse(TextBox2.Text, myDate) Then
    TextBox2.Text = myDate.ToString("d")
End If

Standard Date and Time Format Strings[^]
phil.o 21-Nov-17 12:21pm    
Your goal is unclear. Please clarify.

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