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
 General SQL Server Forums
 New to SQL Server Programming
 date time format change

Author  Topic 

jazzy
Starting Member

2 Posts

Posted - 2008-05-19 : 05:26:01
Would it be possible to change the date time from varchar to datetime. it currently showing as varchar in the following format 20080401 0845
can it be changed to date/time format into something like this 01/04/2008 08:45. If someone could help that would be great. Many thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-19 : 05:32:50
Yes.
Add ":" ASCII(58) between the hour and minute.
Then convert to datetime datatype.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

jazzy
Starting Member

2 Posts

Posted - 2008-05-19 : 06:31:00
so in the view what do i need to do if you could help with what statement i need to put there
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-19 : 06:42:50
Always try to use proper datatype for storing the values.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-19 : 07:01:36
[code]DECLARE @Sample TABLE (Info VARCHAR(13))

INSERT @Sample
SELECT '20080401 0845'

SELECT CONVERT(SMALLDATETIME, STUFF(Info, 12, 0, ':'))
FROM @Sample[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-05-19 : 07:01:51
quote:
Originally posted by jazzy

so in the view what do i need to do if you could help with what statement i need to put there



declare @date varchar(20)
set @date='20080401 0845'
select cast(stuff(@date,12,0,':') as datetime)

As said always use proper DATETIME datatype to store dates

Madhivanan

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

- Advertisement -