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 |
|
xdk1x
Starting Member
9 Posts |
Posted - 2004-06-04 : 06:29:56
|
| Hi!I want to convert an integervalue (20040601) to a date. After that I want to do some calculations with this date:Value = 20040601RowAValue - 2 MonthRowBValue - 1 Year (to the 1. Januar)What would be the easiest way?ThanksDaniel |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2004-06-04 : 06:31:27
|
| select convert(datetime,convert(varchar(8),20040601)) |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-06-04 : 06:39:25
|
| does this work for you?declare @intdate intset @intdate = 20040601declare @date datetimeset @date = convert(datetime,left(convert(varchar, @intdate),4) + '-' + substring(convert(varchar, @intdate),5,2) + '-' + right(convert(varchar, @intdate),2))select @date, dateadd(mm, -2, @date), dateadd(yyyy, -1, @date)Go with the flow & have fun! Else fight the flow :) |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2004-06-04 : 06:41:12
|
| doh... <- imagine homer simpson style :)i really like to complicate things.... :))Go with the flow & have fun! Else fight the flow :) |
 |
|
|
srinivasanr
Starting Member
15 Posts |
Posted - 2004-06-04 : 06:42:56
|
| RickD's solution will work and crack out the nut.Wallops!! |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2004-06-04 : 06:52:17
|
quote: Originally posted by spirit1 doh... <- imagine homer simpson style :)i really like to complicate things.... :))Go with the flow & have fun! Else fight the flow :)
Just a bit more complicated... It's an iso standard dateformat that he has there... |
 |
|
|
xdk1x
Starting Member
9 Posts |
Posted - 2004-06-04 : 08:03:03
|
| Thanks for your fast answers! It works perfect. |
 |
|
|
|
|
|
|
|