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 6119229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:31:42+00:00 2026-05-23T15:31:42+00:00

I am trying to calculate daysbetween difference between two dates in the grid. This

  • 0

I am trying to calculate daysbetween difference between two dates in the grid.
This kind’a works but produces at first strange result:
This is Oncalculate fields event of the TEMP table:

TEMP.FieldByName('DAYS').asstring := IntToStr(Daysbetween(TEMP.FieldByName('BIV_OD').AsDateTime,TEMP.FieldByName('BIV_DO').AsDateTime));

BIV_OD and BIV_DO are date fields (ie. like … Date_From – Date-to)
When I select the first date in the grid (BIV_OD) ,my DAYS field at first show 40731 (??)
Then when i input the second date everything works ok.
Why is that ?

  • 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-05-23T15:31:43+00:00Added an answer on May 23, 2026 at 3:31 pm

    That’s what you asked for…

    Delphi stores dates as the number of days since 31/12/1899 so when you write the first date you are doing 40731(The number of days since 31/12/1899) – 0 since you haven’t yet entered a second date.

    The solution would be not to calculate the field unless both dates are filled in.

    if (Temp.FieldByName('BIV_OD').AsDateTime > 0) and (TEMP.FieldByName('BIV_DO').AsDateTime > 0) then
        TEMP.FieldByName('DAYS').AsString:= IntToStr(Daysbetween(TEMP.FieldByName('BIV_OD').AsDateTime,TEMP.FieldByName('BIV_DO').AsDateTime))
    else
        TEMP.FieldByName('DAYS').AsString:= ''; //don't display anything. 
    

    Although I’d set the grid column to have a data type of integer.

    if (Temp.FieldByName('BIV_OD').AsDateTime > 0) and (TEMP.FieldByName('BIV_DO').AsDateTime > 0) then
        TEMP.FieldByName('DAYS').AsInteger:= Daysbetween(TEMP.FieldByName('BIV_OD').AsDateTime,TEMP.FieldByName('BIV_DO').AsDateTime)
    else
        TEMP.FieldByName('DAYS').Value := Null; //don't display anything. 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to calculate the number of days between two dates like this:
I'm trying to calculate TimeSpans between dates. I have no problem with this if
I am trying to calculate difference(in seconds) between two date/times formatted as following: 2010-05-11
I'm trying to calculate the number of days between two days, but I'm running
I'm trying to calculate the difference between 2 dates, the current date and the
I am trying to calculate difference between two date strings both of which are
I am trying to calculate the difference between given two times and i find
I am trying to calculate the distance between the first GPS point stored in
I'm trying to calculate the distance between two points. The two points I stored
I am trying to calculate the fiscal year from this following code. But I

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.