web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Date Conversion in SQL

(0) ShareShare
ReportReport
Posted on by 12

So to all my sql friends I know this is a simple question, but I am struggling to get it right.

I need to add month or day to the DocDate field in the PM00400 (we are doing work in Excel not on the table)

So I have been trying 

select dateadd(month, 1, docdate) from pm00400

and I get a message 'adding a value to a 'datetime' column caused an overflow.

Recognizing that docdate is a datetime field I have tried

CONVERT(VARCHAR(25), CAST(docdate AS date), 107) - that gives me the date as Jan 01, 2021 - workable but not right yet

So I tried to combine the DATEADD and the above line - and I get the same message.

I know I am close, but what am I missing.

Thanks in advance.

Categories:
I have the same question (0)
  • Kevin Day Profile Picture
    610 on at

    Is it as simple as this?  You can run this against your database.

    SELECT DATEADD(MM, 1, DOCDATE) as [New], DOCDATE as [Old], * FROM PM00400 WHERE DEX_ROW_ID = 1

  • Bill Campbell Profile Picture
    12 on at

    Kevin that works when I do it for 1 or 2 records, but any more and I get 'adding a value to a 'datetime' column caused an overflow'

    Is it possible that there is a limit on the number of date converts that can be done in one single pass?  It is erroring out at 66340 rows - and there are 159,900 rows in the table

  • Joseph Markovich Profile Picture
    4,001 on at

    Hi Bill-

    On a PM00400 table, I did this (there are 101,473 rows):

    dateadd("MONTH", 1, convert(date,docdate))

    It added a month to all of the rows in a new column successfully. Usually when I am querying the GP data I strip off the time in any of the date fields.

    Joe

  • Bill Campbell Profile Picture
    12 on at

    So just for fun, I did some testing and found out that the problem was actually in the DocDate field - one of the Alignment Documents has a date on it of 9999-12-31 and so that fails the system

    Good to know we established the end life of this system - the year 9999, Dec 31 - then we can no longer enter a date.  I think we better get some of the best minds on this to resolve this 'nearly' pressing matter.  Reminds me somewhat of 1999 - but maybe I am just stretching a bit.

    Have a good day all.

  • Bill Campbell Profile Picture
    12 on at

    Joe, I do the same, just wondering if I am doing the most effective way.

    format(DATEADD(MM, 1, DOCDATE),'yyyy-MM-dd') as [New]

    I see we end at the same place - just looking for a 'best or better' way if that is possible.

  • Joseph Markovich Profile Picture
    4,001 on at

    Bill, I have a 12/31/9999 countdown clock in my office.

    :)

    Joe

  • Beat Bucher  GP Geek  GPUG All Star Profile Picture
    28,061 Moderator on at

    Bill,

    Not to be picky.. but does the format really matter ? I mean most of the Excel date fields are driven by the system date settings (be that EN-US or EN-CA, or whatever your country is)..

    I know that SQL stores the dates in a Date-Time field type, so unless this comes from a String (text) field, there is no point in trying to convert the date format..

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 620

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 521 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 430

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans