Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why some date field auto changes to be 1/1/1900.

Status
Not open for further replies.

santosh1

Programmer
Apr 26, 2002
201
0
0
US
I have a date field whose datatype is smalldatetime.
Sometimes, some of the date I have stored auto changes to be 1/1/1900.
Why does this happens, is there a way I can fix this? Thanks in advance.
 
More information please. Do you mean the data is 'stored' in the DB in smalldatetim? I think VB.NET only has 'Date', not 'smalldatetime'. Do you get the values from a textbox or a calendar control?

Might be that you have no value in your date property and when you send the value to the DB, I believe an empty string gets converted to the DB default of 1/1/1900....
 
check to see what value you are passing to the table. If its not a date format then it will show that value.

Scott
Programmer Analyst
<{{><
 
The datatype smalldatetime is in SQL Server table.
Yes, I select the date from calender control.

Right now, the date value I store into the table is
in this way:

'dtInvoiceDate is a calender control

invoicedate = dtInvoiceDate.text

I want to use short date e.g. 4/23/2003 without time value.
If I use dtInvoiceDate.value, it gives me date and time.
Is there a way I can use short date using the value property. I wonder if date.text is causing the problem
 
I have always found the safest way to pass a date value to SQL Server is in the format yyyy-MM-dd. Try passing the date using:
Code:
Dim sDate As String = Convert.ToDateTime(dtInvoiceDate.Text).ToString(&quot;yyyy-MM-dd&quot;)
 
I'm using a datetimepicker. The format property is defined as Custom. When I select this option it defauls the value to 9/23/2003.

I am using a SP to insert data into the table. The parameter that holds the date is defined as datetime. The datatype for that column in the database is smalldatetime.

Try using the custom Format......that should help.


BTW I'm using SQL Server 2k

Scott
Programmer Analyst
<{{><
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top