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 |
|
tonyz
Starting Member
5 Posts |
Posted - 2007-07-04 : 06:18:53
|
| hi everyoneI need to convert date stored as string(varchar) to seconds(int) before I can do some calculationsthe string date looks like this:01/12/2007 10:00:00any ideas?thnxtony |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-07-04 : 06:28:19
|
| So what is the expected output?Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-07-04 : 06:32:10
|
| [code]declare @dt datetimeset @dt = '01/12/2007 10:00:00'select datediff(second, dateadd(day, datediff(day, 0, @dt), 0), @dt) as secondswithinday[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
tonyz
Starting Member
5 Posts |
Posted - 2007-07-04 : 06:42:33
|
| the app stores dates as unix seconds (seconds since 1/1/1970)so, looking to convert the string to seconds since 1/1/1970 |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-07-04 : 06:45:44
|
| [code]declare @dt datetimeset @dt = '01/12/2007 10:00:00'select datediff(second, '19700101', @dt) as TotalSeconds[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
tonyz
Starting Member
5 Posts |
Posted - 2007-07-05 : 05:25:18
|
| thats ok when defining one string.. but I have to troll through 100's of rows to do the comparison, I need something like :declare @dt datetimeset @dt = (select value from ahd.prp where value != '')select datediff(second, '19700101', @dt) as TotalSecondsbut this causes en error complaining about the select (guess u cant use it with a declare statement)basically I have 2 columns, one contains a date that is a string the other has the date in seconds since 1/1/1970how do I write the query comparing all values in these two columns?thnxtony |
 |
|
|
|
|
|
|
|