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.
| 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 0845can 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" |
 |
|
|
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 |
 |
|
|
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. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-19 : 07:01:36
|
[code]DECLARE @Sample TABLE (Info VARCHAR(13))INSERT @SampleSELECT '20080401 0845'SELECT CONVERT(SMALLDATETIME, STUFF(Info, 12, 0, ':'))FROM @Sample[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
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 datesMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|