Monday, February 13, 2012

add 28 years aagin

HI all,
This has puzzled me all morning. I have a int field which reads
19691124 (UK dates) this is actually a date 24 November 1969 I need to
add 28 years to this making it 19971124 but Im stumped!
Any ideas anyone?
Cheers
Sean

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!"S G" <anonymous@.devdex.com> wrote in message news:3f05aafd$0$205$75868355@.news.frii.net...
> HI all,
> This has puzzled me all morning. I have a int field which reads
> 19691124 (UK dates) this is actually a date 24 November 1969 I need to
> add 28 years to this making it 19971124 but I'm stumped!
> Any ideas anyone?
> Cheers
> Sean
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

If you want a DATETIME returned then

SELECT DATEADD(YEAR, 28, '19691124')

If you want an INT returned then

SELECT CAST(CONVERT(CHAR(8),
DATEADD(YEAR, 28, '19691124'),
112) AS INT)

Regards,
jag|||S G wrote:
> HI all,
> This has puzzled me all morning. I have a int field which reads
> 19691124 (UK dates) this is actually a date 24 November 1969 I need
> to add 28 years to this making it 19971124 but I'm stumped!

Select (DateField + 280000) as NewDateField
From Table

By the way, I don't like too much that way of storing dates.

Anyway...

Bye

Alberto|||Sorry, forgot that your input is an INT. Replace the string '19691124'
with CAST(19691124 AS CHAR(8)).

"John Gilson" <jag@.acm.org> wrote in message news:RhiNa.6153$351.2133325@.twister.nyc.rr.com...
> "S G" <anonymous@.devdex.com> wrote in message news:3f05aafd$0$205$75868355@.news.frii.net...
> > HI all,
> > This has puzzled me all morning. I have a int field which reads
> > 19691124 (UK dates) this is actually a date 24 November 1969 I need to
> > add 28 years to this making it 19971124 but I'm stumped!
> > Any ideas anyone?
> > Cheers
> > Sean
> > *** Sent via Developersdex http://www.developersdex.com ***
> > Don't just participate in USENET...get rewarded for it!
> If you want a DATETIME returned then
> SELECT DATEADD(YEAR, 28, '19691124')
> If you want an INT returned then
> SELECT CAST(CONVERT(CHAR(8),
> DATEADD(YEAR, 28, '19691124'),
> 112) AS INT)
> Regards,
> jag|||"Albe V" <vaccariTOGLI_QUESTO@.hotmail.com> wrote in message
news:IqiNa.147480$lK4.4100117@.twister1.libero.it.. .
> S G wrote:
> > HI all,
> > This has puzzled me all morning. I have a int field which reads
> > 19691124 (UK dates) this is actually a date 24 November 1969 I need
> > to add 28 years to this making it 19971124 but I'm stumped!
> Select (DateField + 280000) as NewDateField
> From Table

This approach will be problematic with a leap year, e.g.,
adding 1 year to 20000229.

Regards,
jag

> By the way, I don't like too much that way of storing dates.
> Anyway...
> Bye
> Alberto

No comments:

Post a Comment