0
SELECT 
    CONVERT(VARCHAR, DATEADD(YEAR, 150, CAST(dob AS DATETIME)), 107) 
FROM 
    CUSTOMER

This code results in the following error:

Adding a value to a 'datetime' column caused an overflow

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • What DBMS are you using? Seems to work fine in sql-server with GETDATE()... Have you checked your data for any anomalies? – HereGoes Sep 18 '19 at 17:20
  • What is the data type for `dob` and show the sample data stored. – SS_DBA Sep 18 '19 at 17:21
  • Possible duplicate of [DateAdd Column caused an overflow](https://stackoverflow.com/questions/9119403/dateadd-column-caused-an-overflow) – Steve-o169 Sep 18 '19 at 17:22
  • 1
    [Bad habits to kick : declaring VARCHAR without (length)](https://sqlblog.org/2009/10/09/bad-habits-to-kick-declaring-varchar-without-length) - you should **always** provide a length for any `varchar` variables and parameters that you use – marc_s Sep 18 '19 at 18:00

1 Answers1

0

Your dob column contains one or more dates that are greater than Dec 31, 9849 - this is the latest date that you can add 150 years to and still remain under the maximum value a DATETIME may have, which is 23:59:59.997 on Dec 31, 9999

Caius Jard
  • 72,509
  • 5
  • 49
  • 80