June 4, 2005 at 12:41 am
Hi,
I tried to set a default datetime value for a column. I set '2005-1-1', but on inserting new rows the date is shown as 25/06/1905.
What's wrong?
Dinuj Nath
June 4, 2005 at 6:57 am
If you are setting the default date in enterprise manager try using ("2005-1-1").
HTH Mike
June 4, 2005 at 7:17 am
Thanks for replying but, that's what I have done.
Dinuj Nath
June 4, 2005 at 7:53 am
Sorry but I can not recreate your problem.
HTH Mike
CREATE TABLE #TEST
(
DT datetime default('2005/1/20'),
val int
)
insert into #Test(Val)Values(1)
insert into #Test Values(cast('1/21/99' as datetime),2)
select * from #Test
DROP TABLE #Test
/* returns
2005-01-20 00:00:00.000 1
1999-01-21 00:00:00.000 2
*/
June 5, 2005 at 2:10 am
Try '20050120'
This is the ISO standard way of representing a date as string.
SQLServer takes this format independant of the datetime configuration of the computer.
June 5, 2005 at 8:19 am
Alternately - you can "set dateformat":
SET DATEFORMAT ydm
GO
DECLARE @datevar datetime
SET @datevar = '2005-1-1'
SELECT @datevar
GO
**ASCII stupid question, get a stupid ANSI !!!**
June 6, 2005 at 12:20 am
Thanks folks, the ISO standard worked
Dinuj Nath
June 6, 2005 at 7:16 am
I think Michael's point is valid - if you were using EM, make sure that you let it know it is a string as in
"2005-1-1", NOT 2005-1-1 as it would be 2003, which (I am guessing) may well be 2003 days past 30-12-1899 which is date #0 in sql and many other environments. You would get the same by not having quotes in your SQL statement in query analyser.
Cheers!
June 6, 2005 at 8:10 am
Date "0" for MS SQL Server is Jan. 1, 1900,
NOT Dec. 30, 1899.
June 7, 2005 at 4:34 am
True, it does appear the case in query analyser...
My 1899-12-30 answer came from me using Delphi for 95% of my development - if I retrieve a 0 datetime value from SQL Server that is the date that is retrieved oddly enough.
Anyone know why this is?
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply