Groups | Blog | Home
all groups > sql server (alternate) > july 2003 >

sql server (alternate) : add 28 years aagin


S G
7/4/2003 4:27:41 PM
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 ***
John Gilson
7/4/2003 4:53:05 PM
[quoted text, click to view]

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°
7/4/2003 5:02:32 PM
[quoted text, click to view]

Select (DateField + 280000) as NewDateField
From Table

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

Anyway...

Bye

Alberto

John Gilson
7/4/2003 5:04:48 PM
Sorry, forgot that your input is an INT. Replace the string '19691124'
with CAST(19691124 AS CHAR(8)).

[quoted text, click to view]

John Gilson
7/4/2003 5:14:03 PM
[quoted text, click to view]

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

Regards,
jag

[quoted text, click to view]

AddThis Social Bookmark Button