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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How do I convert from int to date?

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 = 20040601

RowA
Value - 2 Month
RowB
Value - 1 Year (to the 1. Januar)

What would be the easiest way?

Thanks

Daniel

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2004-06-04 : 06:31:27
select convert(datetime,convert(varchar(8),20040601))
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-06-04 : 06:39:25
does this work for you?

declare @intdate int
set @intdate = 20040601
declare @date datetime
set @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 :)
Go to Top of Page

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 :)
Go to Top of Page

srinivasanr
Starting Member

15 Posts

Posted - 2004-06-04 : 06:42:56

RickD's solution will work and crack out the nut.

Wallops!!
Go to Top of Page

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...
Go to Top of Page

xdk1x
Starting Member

9 Posts

Posted - 2004-06-04 : 08:03:03
Thanks for your fast answers! It works perfect.
Go to Top of Page
   

- Advertisement -