|
-
Mar 24th, 2005, 04:50 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] SQL Date Issue
Im having an issue when inserting a date into my sql server table.
the table's date column is set to smalldatetime
so when i try to insert the date 23/03/2005 into the column, when i look on sql server the field contains 01/01/1900
however if i insert 03/23/2005, when i look on sql server the field contains 23/03/2005
why is this happening..... my regional settings are set to GMT.
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Mar 24th, 2005, 10:11 AM
#2
Fanatic Member
Re: SQL Date Issue
There's nothing wrong, thats just the way SQL stores dates.
If wishes were fishes we'd all cast nets.
-
Mar 24th, 2005, 10:14 AM
#3
Thread Starter
Fanatic Member
Re: SQL Date Issue
but why is it requiring me to insert the date in american format.
why cant i insert as the european format
when i insert as european date it gives me an error as it recognises that the 23 is not a month
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Mar 24th, 2005, 10:15 AM
#4
Re: SQL Date Issue
 Originally Posted by Strider
but why is it requiring me to insert the date in american format.
why cant i insert as the european format
when i insert as european date it gives me an error as it recognises that the 23 is not a month
SQL Server is very date biased to the American format.
We always use YYYY-MM-DD when doing date INSERT's - so that ambiguity does not become a problem.
-
Mar 24th, 2005, 10:18 AM
#5
Thread Starter
Fanatic Member
Re: SQL Date Issue
to make things all the more strange.......
my application was working fine for the past two weeks then suddenly in the past few days its wont allow me to insert a date.now() into the date field....
i get the error i previously mentioned....
however, however...... when u insert date.today() it sets the date in the field to the 01/01/1900 ...and that aint the right date....
what the hell is going on.
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Mar 24th, 2005, 10:21 AM
#6
Re: SQL Date Issue
 Originally Posted by Strider
to make things all the more strange.......
my application was working fine for the past two weeks then suddenly in the past few days its wont allow me to insert a date.now() into the date field....
i get the error i previously mentioned....
however, however...... when u insert date.today() it sets the date in the field to the 01/01/1900 ...and that aint the right date....
what the hell is going on.
01/01/1900 is a "blank" date getting inserted into the date field.
-
Mar 24th, 2005, 10:26 AM
#7
Thread Starter
Fanatic Member
Re: SQL Date Issue
what do you mean by blank date????
i just dont understand why date.today() gives me 01/01/1900 and date.now() gives me the error that there is no such month as the 23rd
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Mar 24th, 2005, 10:37 AM
#8
Fanatic Member
Re: SQL Date Issue
Instead of letting using date.now() or whatever just use SQLs built in Now()
ie.
strSQL = "INSERT INTO TableX VALUES(" + id + ",'" + var1 + "',Now()," + var2 + ")"
If wishes were fishes we'd all cast nets.
-
Mar 24th, 2005, 10:42 AM
#9
Thread Starter
Fanatic Member
Re: SQL Date Issue
in my try catch i get the following error when using the Now() sql function
'Now' is not a recognized function name
here is my sql stmt
Dim selectString As String = _
"UPDATE tbl_UsersCompany SET " & _
"Company='" & SafeSqlLiteral(p_customer.Company) & "', " & _
"Address1='" & SafeSqlLiteral(p_customer.Addr1) & "', " & _
"Address2='" & SafeSqlLiteral(p_customer.Addr2) & "', " & _
"Address3='" & SafeSqlLiteral(p_customer.Addr3) & "', " & _
"Town='" & SafeSqlLiteral(p_customer.Town) & "', " & _
"RegionID= " & p_customer.Region & ", " & _
"Phone='" & SafeSqlLiteral(p_customer.Phone) & "', " & _
"Fax='" & SafeSqlLiteral(p_customer.Fax) & "', " & _
"Email='" & SafeSqlLiteral(p_customer.Email) & "', " & _
"URL='" & SafeSqlLiteral(p_customer.URL) & "'," & _
"Active= " & l_active & ", " & _
"SupportAgreement= " & l_suppAgreement & ", " & _
"LastModified= Now(), " & _
"LastModifiedUserId= 138" & _
" WHERE UCID= " & p_customer.UCID '& "'"
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Mar 24th, 2005, 10:48 AM
#10
Fanatic Member
If wishes were fishes we'd all cast nets.
-
Mar 24th, 2005, 10:56 AM
#11
Thread Starter
Fanatic Member
Re: SQL Date Issue
yup had a look there....its getDate() in sql and its works fine....coola peoples cheeers
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Mar 24th, 2005, 11:08 AM
#12
Re: SQL Date Issue
 Originally Posted by Strider
yup had a look there....its getDate() in sql and its works fine....coola peoples cheeers
Just to further the point...
GETDATE() is the SERVER time - not the workstation or PC time.
It's always more appropriate, in my opinion, to use the server time and not the workstation time.
-
Mar 24th, 2005, 11:10 AM
#13
Thread Starter
Fanatic Member
Re: SQL Date Issue
ya i think ill use that more often instead
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Jun 15th, 2005, 02:02 AM
#14
New Member
Re: SQL Date Issue
Hi,
I went throught your reply I have the same problem. Now in my case the system has been running for 4 months and this month on the 13th of june it started giving problems. When I checked the database (MS SQL) I found the date had reversed only for this month instead of saving as 6/1/2005 (June 1 2005) it started saving as 1/6/2005 (January 6 2005) and so when it came to 13 of this month the system gives an error message date out of range.
When saving data I format it to yyyy/mm/dd as this format is international according to MSDN. I would appreciate if anyone can point out something that might help.
Thanks
-
Jun 15th, 2005, 03:56 AM
#15
Thread Starter
Fanatic Member
Re: SQL Date Issue
are you using the getdate() function because it will get the time from the sql server and insert that into the datetime field in the format of the regional settings on the server
just make sure to do a check on your server that the regional settings are set to UK or Ireland and not US so that the date format is dd/mm/yyyy.
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|