Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8172749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:53:12+00:00 2026-06-06T21:53:12+00:00

The query returns no results even on the ones where it does work and

  • 0

The query returns no results even on the ones where it does work and I am getting the following error.

The datediff function resulted in an overflow. The number of
dateparts separating two date/time instances is too large. Try to use
datediff with a less precise datepart.

But there is nothing to overflow

The following work:

SELECT cis.SaleBK   
FROM dbo.Sales cis
INNER JOIN dim.CalendarDate sd on cis.SaleDateFK = sd.CalendarDatePK
WHERE sd.CalendarDate >= DATEADD(day,-1,dbo.DateToday())

And this one:

SELECT cis.SaleBK
       ,DATEDIFF(s,'1969-01-01',sd.CalendarDate) as SortOrder
FROM dbo.Sales cis
INNER JOIN dim.CalendarDate sd on cis.SaleDateFK = sd.CalendarDatePK
WHERE sd.CalendarDate = DATEADD(day,-1,dbo.DateToday())

But this does not and I can’t figure out why

SELECT cis.SaleBK
       ,DATEDIFF(s,'1969-01-01',sd.CalendarDate) as SortOrder
FROM dbo.Sales cis
INNER JOIN dim.CalendarDate sd on cis.SaleDateFK = sd.CalendarDatePK
WHERE sd.CalendarDate >= DATEADD(day,-1,dbo.DateToday())
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:53:14+00:00Added an answer on June 6, 2026 at 9:53 pm

    I wrote a loop to check when datediff returns an error:

    ; with  Dates as
            (
            select  cast('2012-01-01' as date) as dt
            union all
            select  dateadd(day, 1, dt)
            from    Dates
            )
    select  dt
    ,       DATEDIFF(s,'1969-01-01',dt)
    from    Dates
    option  (maxrecursion 0)
    

    The number of seconds since 1969-01-01 and 2037-01-20 is the first that is too large.

    So it looks like the maximum number returned by DateDiff is 2^31 or 2147483647.

    You can avoid the error by limiting the query’s date range, like:

    WHERE  sd.CalendarDate >= DATEADD(day,-1,dbo.DateToday())
           and sd.CalendarDate < '2037-01-20'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running the following query and checking whether it returns any results and
I need a Java function that returns the results of a SQL SELECT query
I have the following Sql Query that returns the type of results that I
I'm running an MySQL query that returns results based on location. However I have
How would I go about doing a query that returns results of all rows
I have this query that returns the results by ordering it by focus.name ASC.
I have a method that basically returns the results of a mysql query. public
With T-SQL, is it possible to write a query that returns results that look
I have a query that returns results related to items that match a specific
Mysql query returns result like this collector amount name 1 0.00 gihan 1 2000.00

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.