Showing posts with label puzzled. Show all posts
Showing posts with label puzzled. Show all posts

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

add 28 years

HI all,
This has puzzled me all morning. I have an 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
SeanWhat about this
SELECT CONVERT(Char(10),DATEADD(Year,28,'19691124'),112)
--
Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org
"Sam" <sgpgpjr@.yahoo.ie> wrote in message
news:07b701c34248$97333560$a001280a@.phx.gbl...
> HI all,
> This has puzzled me all morning. I have an 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
>|||DECLARE @.years INT
SET @.years =28
SELECT DATEADD(yy, @.years, CAST(int_column AS varchar(10)))
or if you want to keep it as an int:
SELECT int_column + (@.years * 10000)
Jacco Schalkwijk MCDBA, MCSD, MCSE
Database Administrator
Eurostop Ltd.
"Sam" <sgpgpjr@.yahoo.ie> wrote in message
news:07b701c34248$97333560$a001280a@.phx.gbl...
> HI all,
> This has puzzled me all morning. I have an 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
>