Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 cast datetime question

Author  Topic 

yipchunyu
Yak Posting Veteran

80 Posts

Posted - 2005-07-20 : 13:20:27
I have a table with field inputed with sth like "12:00 PM"
when I cast it as datetime it display sth like "1899/1/1 12:00PM"
However, when I just do sth like select Cast("12:00 PM" as datetime) it returns like "1900/1/1 12:00PM"
Why it have a day diff?
Any advice?
thx

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2005-07-20 : 13:36:37
One of your words is new to me: "...display sth like..." and "...do sth like..."

What does "sth" mean?


quote:
Originally posted by yipchunyu

I have a table with field inputed with sth like "12:00 PM"
when I cast it as datetime it display sth like "1899/1/1 12:00PM"
However, when I just do sth like select Cast("12:00 PM" as datetime) it returns like "1900/1/1 12:00PM"
Why it have a day diff?
Any advice?
thx



CODO ERGO SUM
Go to Top of Page

yipchunyu
Yak Posting Veteran

80 Posts

Posted - 2005-07-20 : 19:27:35
sth = something for me
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-07-21 : 01:39:55
What is the datatype of that field?
It should display the default date
declare @t table(d datetime)
insert into @t values('12:00 PM')
select cast(d as datetime) from @t
Select cast('12:00 PM' as datetime)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -