Author |
Topic |
wawansur
Starting Member
44 Posts |
Posted - 2009-09-07 : 04:00:54
|
Could we convert data type from datetime to integer or bigint?I'm nothing just gonna being |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-09-07 : 04:01:34
|
how do you want to convert ? example ? KH[spoiler]Time is always against us[/spoiler] |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-09-07 : 04:02:43
|
or maybeselect convert(int, convert(varchar(10), getdate(), 112))? KH[spoiler]Time is always against us[/spoiler] |
|
|
wawansur
Starting Member
44 Posts |
Posted - 2009-09-07 : 04:33:39
|
I have data like this.FPostID1900-01-01 00:12:30.9131900-01-01 00:12:30.9501900-01-01 00:12:30.9671900-01-01 00:12:31.0001900-01-01 00:12:31.1031900-01-01 00:12:30.5331900-01-01 00:12:30.4971900-01-01 00:12:31.1571900-01-01 00:12:31.1731900-01-01 00:12:31.2971900-01-01 00:12:31.313i want to convert this data into int or bigint, so i could sort itI'm nothing just gonna being |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-09-07 : 04:40:36
|
order by convert(int,replace(replace(replace(replace(FPostID,'-',''),' ',''),':',''),'.','')) No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-09-07 : 04:49:44
|
quote: Originally posted by wawansur I have data like this.FPostID1900-01-01 00:12:30.9131900-01-01 00:12:30.9501900-01-01 00:12:30.9671900-01-01 00:12:31.0001900-01-01 00:12:31.1031900-01-01 00:12:30.5331900-01-01 00:12:30.4971900-01-01 00:12:31.1571900-01-01 00:12:31.1731900-01-01 00:12:31.2971900-01-01 00:12:31.313i want to convert this data into int or bigint, so i could sort itI'm nothing just gonna being
Why dont you sort as datetime?MadhivananFailing to plan is Planning to fail |
|
|
wawansur
Starting Member
44 Posts |
Posted - 2009-09-07 : 04:52:10
|
select*from StckKlrorder by convert(int,replace(replace(replace(replace(FPostID,'-',''),' ',''),':',''),'.',''))I Have this error messagesServer: Msg 245, Level 16, State 1, Line 1Syntax error converting the varchar value 'Jan119001212AM' to a column of data type int.I'm nothing just gonna being |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-09-07 : 04:57:59
|
order by convert(datetime,FPostID)(Thx for that madhi, I was blind ) No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
wawansur
Starting Member
44 Posts |
Posted - 2009-09-07 : 05:02:01
|
quote: Originally posted by webfred order by convert(datetime,FPostID)(Thx for that madhi, I was blind ) No, you're never too old to Yak'n'Roll if you're too young to die.
Its worksThxI'm nothing just gonna being |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-09-07 : 05:05:08
|
quote: Originally posted by webfred order by convert(datetime,FPostID)(Thx for that madhi, I was blind ) No, you're never too old to Yak'n'Roll if you're too young to die.
No problem MadhivananFailing to plan is Planning to fail |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-09-07 : 05:06:56
|
quote: Originally posted by wawansur
quote: Originally posted by webfred order by convert(datetime,FPostID)(Thx for that madhi, I was blind ) No, you're never too old to Yak'n'Roll if you're too young to die.
Its worksThxI'm nothing just gonna being
If FPostID is of datetime data, you dont need any convertionSimply useorder by FPostIDMadhivananFailing to plan is Planning to fail |
|
|
|