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)
 Separate Date and Time from datetime field

Author  Topic 

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2005-02-20 : 22:13:37
Good day!

DateTimeIn
-------------------
2/19/2003 8:00:00 AM
2/20/2003 8:00:00 AM
2/21/2003 8:00:00 AM



I want to separate the date and time...
result should look exactly like this...

DateIn TimeIn
-------------------
2/19/2003 8:00:00 AM
2/20/2003 8:00:00 AM
2/21/2003 8:00:00 AM









Want Philippines to become 1st World COuntry? Go for World War 3...

Ex
Posting Yak Master

166 Posts

Posted - 2005-02-20 : 22:21:55
could use substring
.. assumping @dateIn is the input
DECLARE @dateOut varchar(2)

select @dateOut = SUBSTRING(@dateIn,1,1) + '/' + SUBSTRING(@dateIn,3,2) + '/' + SUBSTRING(@dateIn,6,4) +
'/' + SUBSTRING(@dateIn,6,4)

that woud give you the date
and do somethig similar for the time
Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2005-02-20 : 22:34:22
Ooooooppppsss... i forgot.

How about not using a substring coz i already new that. Is there other way? if possible the shortest and simple way.


tnx.



Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-02-21 : 04:15:17
if DateTimeIn is datetime then:

select convert(varchar(10), DateTimeIn, 101), convert(varchar(15), DateTimeIn, 108)

if it's a varchar then use substring or left() and right() functions.

Go with the flow & have fun! Else fight the flow
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-02-21 : 10:09:23
Most applications used to present data that has been retrieved from Sql Server are much better at formatting values. Are the your users of this data simply executing your query/SP or can you let your presentation software handle the formatting?

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -