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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:19:19+00:00 2026-05-27T16:19:19+00:00

This is a follow up to a previous question: Disparity between date/time calculations in

  • 0

This is a follow up to a previous question: Disparity between date/time calculations in C# versus Delphi

I am porting an enterprise application written in Delphi to C#. The application uses a very rudimentary form of encryption for storing the text files it generates. This encryption is based around the Delphi SecondsBetween command, which returns the number of seconds between two dates.

The problem for me is that in the older version of Delphi (the one I’m porting from), there is a bug with the SecondsBetween command which causes it to return values that are off by one – but only about 50% of the time

The bug is a rounding bug. Delphi originally used Trunc instead of Round. See more detail here – http://qc.embarcadero.com/wc/qcmain.aspx?d=59310

Here is the code to demonstrate the problem:

Delphi:

SecondsBetween(StrToDateTime('16/02/2009 11:25:34 p.m.'), StrToDateTime('1/01/2005 12:00:00 a.m.'));

130289133

C#:

TimeSpan span = DateTime.Parse("16/02/2009 11:25:34 p.m.").Subtract(DateTime.Parse("1/01/2005 12:00:00 a.m."));

130289134

What I’d like to do is figure out how I can emulate this buggy behavior in C# so that I can read/write the text files written by the Delphi application.

  • 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-27T16:19:19+00:00Added an answer on May 27, 2026 at 4:19 pm

    This is translation of the required functions (SpanOfNowAndThen, SecondSpan) to replicate the Delphi 2007 SecondsBetween function.

    using System;
    using System.Text;
    
    namespace D2007SecondsBetween
    {
        class Program
        {
          const double HoursPerDay   = 24;
          const double MinsPerHour   = 60;
          const double SecsPerMin    = 60;
          const double MSecsPerSec   = 1000;
          const double MinsPerDay    = HoursPerDay * MinsPerHour;
          const double SecsPerDay    = MinsPerDay * SecsPerMin;
    
            static double SpanOfNowAndThen(Double ANow, Double AThen)
            {
              if (ANow < AThen)
                return AThen - ANow;
              else
                return ANow - AThen;
            }
    
    
            static double SecondSpan(Double ANow, Double AThen)
            {
             return  SecsPerDay * SpanOfNowAndThen(ANow, AThen);
            }
    
            static int SecondsBetween(DateTime ANow, DateTime AThen)
            {
              return (int)Math.Truncate(SecondSpan(ANow.ToOADate(), AThen.ToOADate()));
            }
    
            static void Main(string[] args)
            {
                TimeSpan span ;            
                span = DateTime.Parse("16/02/2009 23:25:34").Subtract(DateTime.Parse("1/01/2005 00:00:00"));
                Console.WriteLine(span.TotalSeconds);//returns 130289134
                Console.WriteLine(SecondsBetween(DateTime.Parse("16/02/2009 23:25:34"), DateTime.Parse("1/01/2005 00:00:00")));//returns 130289133
    
                span = DateTime.Parse("16/11/2011 23:25:43").Subtract(DateTime.Parse("1/01/2005 00:00:00"));
                Console.WriteLine(span.TotalSeconds);//returns 216948343
                Console.WriteLine(SecondsBetween(DateTime.Parse("16/11/2011 23:25:43"), DateTime.Parse("1/01/2005 00:00:00")));//returns 216948343
    
                Console.ReadKey();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a follow up question to a previous question I asked about calculating
This is a follow-up to a previous question I had about interfaces. I received
This is a follow up to my previous question: Problem passing parameters via Iframe
This is a follow on to my previous question: JSP / servlet / IE
This is a follow on from my previous question although this is about something
This question is a follow up to my previous question about getting the HTML
This is really a follow on question to a previous one , where I
This is a follow-up question to my previous question: Cancel an already executing task
This is a follow up for my previous question: Blob and Storage Requirement I
This is a follow up on my previous question: How do you map areas

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.