Hi there.
I have a VB6 application which works with datetime values in SQL Server (which are obviously storing dates as mm/dd/yyyy).
I need to represent these dates to the user as dd/mm/yyyy, read them in as dd/mm/yyyy, and then store them back into the database as the standard mm/dd/yyyy.
This is the current code snippets I have which pull + insert the dates, however I have read many conflicting methods of handling the conversions, and I was wondering if anyone here knew a clear solution for this situation.
"SELECT * FROM List WHERE DateIn LIKE '%" & txtDateIn.Text & "%'"
"UPDATE [Progress] SET [Date] = '" & txtDate.Text & "'"
txtDate.Text = "" & RecordSet.Fields("Date").Value
Any thoughts? Thanks in advance.
**Update
Actually I just noticed I do have dates stored in datetime fields in the form of 16/08/2009 00:00:00 which is dd/mm/yyyy. So perhaps I misunderstood the problem. But when trying to update the datetime value I have been getting 'The conversion of char data type to a datetime data type resulted in an out-of-range datetime value.'.
I assumed this was because the date formats did not match (causing a problem with having a month value out of range) however I do have date values in the format of day/month/year in the datetime field already. And the date being submitted to the database is definitely dd/mm/yyyy.
** Update 2
Ok, there seems to be some confusion I have caused. I apologize.
- I am storing the dates as datetime in the SQL database
- The texts are TextBox controls in the VB6 application
- I am running SQL SELECT statements to read the dates from the database and place the value in a TextBox
- I then have a 'commit' command button which then performs an UPDATE SQL statement to place the value of the TextBox into the datetime field in the SQL database
- This works perfectly fine until 1 specific occasion.
In this occasion I have a datetime value (which SQL Server 2005 displays as 16/08/2009 00:00:00) which is read from the database and populated the TextBox with the value 16/08/2009. Now when I try to run the UPDATE statement without modifying the TextBox text I get the error 'The conversion of char data type to a datetime data type resulted in an out-of-range datetime value.'
This does not occur with other records such as one where the date is 04/08/2009 so the only issue I can see is possibly with the position of day and month in the value because if the DB is expecting month first then obviously 16/08/2009 would be out-of-range. However the value in the database is already 16/08/2009 with no issues.