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 2005 Forums
 Transact-SQL (2005)
 Just Date and Just Time

Author  Topic 

hamid.y
Starting Member

22 Posts

Posted - 2010-03-01 : 09:03:07
plz tell me how can I save only Date part of datetime datatype?
as an example if the datetime is this:
2010-03-07 17:18:41.473

i need save
2010-03-07
and
17:18:41.473
into two fields separately.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-03-01 : 09:06:18
The easy way is to get sql server 2008.
The hard way is to search about it because there are tons of threads about this.
But wait a moment and someone will post a "workaround"


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

hamid.y
Starting Member

22 Posts

Posted - 2010-03-01 : 09:12:39
how it possible with sql 2008?
sql 2008 has separate date datatype and time datatype?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-01 : 09:14:26
quote:
Originally posted by hamid.y

how it possible with sql 2008?
sql 2008 has separate date datatype and time datatype?



Yes

Madhivanan

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

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-03-01 : 09:14:28
YES


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-03-01 : 09:15:00
2 seconds


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

hamid.y
Starting Member

22 Posts

Posted - 2010-03-01 : 09:15:11
thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-03-01 : 09:15:55
The smiley symbol made difference

Madhivanan

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

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-03-01 : 09:16:45
quote:
Originally posted by hamid.y

plz tell me how can I save only Date part of datetime datatype?
as an example if the datetime is this:
2010-03-07 17:18:41.473

i need save
2010-03-07
and
17:18:41.473
into two fields separately.



in SQL 2005, the best you can do is

declare @datetime datetime

select @datetime = '2010-03-07 17:18:41.473'

select date_only = dateadd(day, datediff(day, 0, @datetime), 0),
time_only = @datetime - dateadd(day, datediff(day, 0, @datetime), 0)



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -