TSE: Date: How to get the total difference in days between 2 given dates? Method: Browser: Online

14 views
Skip to first unread message

knud van eeden

unread,
Jul 4, 2025, 12:52:25 PM7/4/25
to SemWare TSE Pro Text Editor
 Q. TSE: Date: How to get the total difference in days between 2 given dates? Method: Browser: Online

 E.g. if you choose a begin date 1 1 1970 and an end date 15 1 2020, what is the total amount of days between these 2 given dates?

      Passing this as 6 consecutive parameters in the same order:


        (you have to copy/paste this whole line as a one-liner in your browser URL input(anywhere in the world, e.g. mobile telephone). It runs on TSE on a remote Microsoft Windows server)

        gives 18276 days

 with friendly greetings
 Knud van Eeden




Claus Futtrup

unread,
Jul 4, 2025, 1:22:29 PM7/4/25
to sem...@googlegroups.com
Hi Knud

>gives 18276 days

Is the answer correct?

I get 18277 days.


1970 365
1971 365
1972 366 leap year
1973 365
1974 365
1975 365
1976 366
1977 365
1978 365
1979 365
1980 366
1981 365
1982 365
1983 365
1984 366
1985 365
1986 365
1987 365
1988 366
1989 365
1990 365
1991 365
1992 366
1993 365
1994 365
1995 365
1996 366
1997 365
1998 365
1999 365
2000 366 Every 100 year not, but every 1000 year YES!
2001 365
2002 365
2003 365
2004 366
2005 365
2006 365
2007 365
2008 366
2009 365
2010 365
2011 365
2012 366
2013 365
2014 365
2015 365
2016 366
2017 365
2018 365
2019 365
2020 15

18277


With kind regards,
Claus
--

---
You received this message because you are subscribed to the Google Groups "SemWare TSE Pro text editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to semware+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/semware/747699452.250154.1751647879033%40mail.yahoo.com.


knud van eeden

unread,
Jul 4, 2025, 2:07:58 PM7/4/25
to sem...@googlegroups.com
Other source confirms it:

see attachment 

with friendly greetings 
Knud van Eeden






Sent from Yahoo Mail on Samsung Galaxy S24 Ultra / 1 terabyte / artificial intelligence

Claus Futtrup

unread,
Jul 5, 2025, 5:58:26 AM7/5/25
to sem...@googlegroups.com
Hi Knud

Instead of relying on a google output, how about counting days yourself, like I did?
You don't have to count every single day one-by-one...

There is one open question. Are both specified dates included, or excluded?
In mathematics, set theory describes what is called open and closed sets.
When you specify 1) start date, and 2) end date, are both dates included in the set?

Both start and end included are symbolized by closed square brackets, like this : [start ; end]
If both dates are excluded, one uses open square brackets, like this : ]start ; end[
In between we have:

]start ; end]
[start ; end[

I included both start and end date in the set count of days, hence I arrive at 18277 days.

With kind regards,
Claus

knud van eeden

unread,
Jul 5, 2025, 8:04:55 AM7/5/25
to sem...@googlegroups.com
Yes, because only 1 day difference it suggests it is or was a matter of 

1. including or excluding the first day

and or 

2. including or excluding the last day.

That gives 2 . 2 = 4 possibilities or thus plus or minus 2 days to the end result.

I seem to have chosen one of those 4 options, and you another one.

Feel free to add 1 to the end result in the getmatda.s program for example and recompile.

Thanks 

with friendly greetings 
Knud van Eeden

Sent from Yahoo Mail on Samsung Galaxy S24 Ultra / 1 terabyte / artificial intelligence

On Sat, Jul 5, 2025 at 11:58, Claus Futtrup

knud van eeden

unread,
Jul 5, 2025, 8:16:56 AM7/5/25
to sem...@googlegroups.com
And my choice fulfills a very important criterium, that is what is the difference between two the SAME dates?

I assume about everyone would agree that must be zero (=0) days.

And I just tested it on my mobile telephone and it gives zero indeed: 


I assume your calculation would thus give 1,
which would be possibly less expected I assume.







Sent from Yahoo Mail on Samsung Galaxy S24 Ultra / 1 terabyte / artificial intelligence

knud van eeden

unread,
Jul 5, 2025, 8:32:04 AM7/5/25
to sem...@googlegroups.com
additionally testing what is the difference between: 

3 7 2025 and 5 7 2025 gives 2 days difference 

4 7 2025 and 5 7 2025 gives 1 day difference 

5 7 2025 and 5 7 2025 gives thus 0 days difference 

5 7 2025 and 6 7 2025 gives 1 day difference 

5 7 2025 and 7 7 2025 gives 2 days difference 

So that all looks correct and as expected.

Sent from Yahoo Mail on Samsung Galaxy S24 Ultra / 1 terabyte / artificial intelligence

On Sat, Jul 5, 2025 at 14:16, knud van eeden

Claus Futtrup

unread,
Jul 5, 2025, 9:21:44 AM7/5/25
to sem...@googlegroups.com
Hi Knud

Clarification of what is intended with your macro is good.

>5 7 2025 and 5 7 2025 gives thus 0 days difference

Understood.

How one would expect the algorithm depends on what it is meant to do. My expectation is (at least was) that one thinks of both days included, and it could be that when you specify a start-date, it is the very beginning of the day, and the end-date is at the very end of the day = set theory with closed ends, meaning that specifying 5 7 2025 and 5 7 2025 gives thus 24 hours = 1 one day within the set.

In other words - if the macro does what you want it to do, all that remains is to ensure documentation of the intended behavior such that others know what is intended to happen.

With kind regards,
Claus

knud van eeden

unread,
Jul 5, 2025, 9:58:19 AM7/5/25
to sem...@googlegroups.com
Yes,  not always is everything fully documented and instead left e.g. implicitly and or not mentioned.

At the time I implemented most of the date algorithms from a computer book:

[book: Czes Cosniowski - Essential maths on the BBC and Electron computers - page 101 and others]

When it works I usually move on to the next thing.

Note: Your method has at least one big advantage, we get 1 extra day vacation, yes! :-) :-) :-)

with friendly greetings
Knud van Eeden


Sent from Yahoo Mail on Samsung Galaxy S24 Ultra / 1 terabyte / artificial intelligence

On Sat, Jul 5, 2025 at 15:21, Claus Futtrup

knud van eeden

unread,
Jul 5, 2025, 10:23:54 AM7/5/25
to sem...@googlegroups.com

Further give at least 3 randomly chosen websites on the Internet also the same 18276 days as an answer.

If you find at least one website showing instead 18277 days please let me know.

Thanks
with friendly greetings 
Knud van Eeden








Sent from Yahoo Mail on Samsung Galaxy S24 Ultra / 1 terabyte / artificial intelligence

On Sat, Jul 5, 2025 at 15:58, knud van eeden

knud van eeden

unread,
Jul 5, 2025, 10:54:05 AM7/5/25
to sem...@googlegroups.com
Conclusion:

1. 18276 is correct and the most common answer everywhere. It does not include the last day.

2. 18277 is also correct, but a less common answer. It includes thus the last day.

It is like in English when you say:

"between Monday and Wednesday"

That is thus an *ambiguous* expression.

Does it include Wednesday or not?

One has thus to explicitly express what is meant sometimes:

"between Monday and Wednesday (included)"

or

"between Monday and Wednesday (not included)"

"between Monday and Wednesday (excluded)"

Even more precise would be: 

"between Monday (included) and Wednesday (included)". Gives 3 days.

"between Monday (included) and Wednesday (excluded)". Gives 2 days.

"between Monday (excluded) and Wednesday (included)". Gives 2 days.

"between Monday (excluded) and Wednesday (excluded)". Gives 1 day.

Thus 4 basically equivalent possibilities.

Sent from Yahoo Mail on Samsung Galaxy S24 Ultra / 1 terabyte / artificial intelligence

On Sat, Jul 5, 2025 at 16:23, knud van eeden

S.E. Mitchell

unread,
Jul 5, 2025, 11:07:06 AM7/5/25
to sem...@googlegroups.com
/**************************************************************************
  Convert a y-m-d (y in 1..3000?, m in 1..12, d in 1..31) to a Julian
  Date.
 **************************************************************************/
integer proc jd(integer y, integer m, integer d)
     return (( 1461 * ( y + 4800 + ( m - 14 ) / 12 ) ) / 4 +
          ( 367 * ( m - 2 - 12 * ( ( m - 14 ) / 12 ) ) ) / 12 -
          ( 3 * ( ( y + 4900 + ( m - 14 ) / 12 ) / 100 ) ) / 4 +
          d - 32075)
end

/**************************************************************************
  Convert a Julian date to the corresponding Gregorian y-m-d.
 **************************************************************************/
proc gd(integer jd, var integer y, var integer m, var integer d)
    integer i, l, n, j

        l = jd + 68569
        n = ( 4 * l ) / 146097
        l = l - ( 146097 * n + 3 ) / 4
        i = ( 4000 * ( l + 1 ) ) / 1461001     //(that's 1,461,001)
        l = l - ( 1461 * i ) / 4 + 31
        j = ( 80 * l ) / 2447
        d = l - ( 2447 * j ) / 80
        l = j / 11
        m = j + 2 - ( 12 * l )
        y = 100 * ( n - 49 ) + i + l           //(that's a lower-case L)
end

proc main()
    integer x, y

    x = jd(1970, 1, 1)
    y = jd(2020, 1, 15)
    warn(y - x)
end

Shows: 18276

Based on this:

Julian Day Numbers
            by Peter Meyer

    Introduction
                    History
                    Astronomical Sytem
                    Modified Julian Day Number
                    Lillian Day Number
                    Computation

    Introduction
    Astronomers and chronologists use a system of numbering days called Julian
    days or Julian day numbers. The temporal sequence of days is mapped onto the
    sequence of integers, -2, -1, 0, 1, 2, 3, etc. This makes it easy to
    determine the number of days between two days (just subtract one Julian day
    number from the other).
    For example a solar eclipse is said to have been seen at Ninevah on Julian
    day 1,442,454 and a lunar eclipse is said to have been observed at Babylon
    on Julian day number 1,566,839 (these numbers correspond to the Julian
    Calendar dates -763-03-23 and -423-10-09 respectively). Thus the lunar
    eclipse occurred 124,384 days after the solar eclipse.
    Generally speaking, an integer date is any system of assigning a one-to-one
    correspondence between the days of our experience (more strictly, solar
    days) and the integers. Such systems differ only in the day chosen to
    correspond to day 0 or day 1. For example, in some applications NASA uses
    the Truncated Julian Date, which is the number of days since midnight on
    1968-05-24 (at which time the Apollo missions to the Moon were underway).
    Other starting dates popular with computer programmers are, or have been,
    1601-01-01 (Gregorian), 1900-01-01, 1901-01-01 and 1980-01-01. The choice is
    usually a consequence of the temporal precision required (days to
    microseconds), the application period (a decade, a century, a millennium,
    etc.) and the number of bytes available for storing the date.
    The system of Julian days should not be confused with the simpler system of
    the same name which associates a date with the number of days elapsed since
    January 1st of the same year (according to which 2000-12-31 is day 366 ù of
    the year 2000).

    History
    The Julian Day number system was invented by Joseph Justus Scaliger (born
    1540-08-05 J in Agen, France, died 1609-01-21 J in Leiden, Holland), who
    during his life immersed himself in Greek, Latin, Persian and Jewish
    literature. His invention (in 1583) of the Julian day number system is
    considered by some the foundation of the science of chronology.
    Although the term Julian Calendar derives from the name of Julius Caesar,
    the term Julian day number probably does not. Most say that this system was
    named, not after Julius Caesar, but after its inventor's father, Julius
    Caesar Scaliger (1484-1558). Perhaps it was simply named after the Julian
    Calendar.
    The younger Scaliger combined three traditionally recognized temporal cycles
    of 28, 19 and 15 years to obtain a great cycle, the Scaliger cycle, or
    Julian period, of 7980 years (7980 is the least common multiple of 28, 19
    and 15). According to the Encyclopedia Brittanica:
        The length of 7,980 years was chosen as the product of 28 times 19 times
        15; these, respectively, are the numbers of years in the so-called solar
        cycle of the Julian calendar in which dates recur on the same days of
        the week; the lunar or Metonic cycle, after which the phases of the Moon
        recur on a particular day in the solar year, or year of the seasons; and
        the cycle of indiction, originally a schedule of periodic taxes or
        government requisitions in ancient Rome.
    The first Scaliger cycle began with Year 1 on -4712-01-01 (Julian) and will
    end after 7980 years on 3267-12-31 (Julian), which is 3268-01-22
    (Gregorian). 3268-01-01 J is the first day of Year 1 of the next Scaliger
    cycle.

    Astronomical Sytem
    Little mention seems to be made as to whether Joseph Scaliger regarded
    -4712-01-01 J as day 0 or as day 1 in the first Julian period. Astronomers
    adopted this system and adapted it to their own purposes, and they took noon
    GMT -4712-01-01 as their zero point. For astronomers a day begins at noon
    and runs until the next noon (so that the nighttime falls conveniently
    within one "day"). Thus they defined the Julian day number of a day as the
    number of days (or part of a day) elapsed since noon GMT (or more exactly,
    UTC) on January 1st, 4713 B.C., in the Proleptic Julian Calendar. Thus the
    Julian day number of noon GMT on -4712-01-01 (Julian), or more casually, the
    Julian day number of -4712-01-01 itself, is 0. (Note that 4713 B.C. is the
    year -4712 according to the astronomical year numbering.) The Julian day
    number of 1996-03-31 is 2,450,174 ù meaning that on 1996-03-31 2,450,174
    days had elapsed since -4712-01-01 (or more exactly, that at noon on
    1996-03-31 2,450,174 days had elapsed since noon on -4712-01-01).
    Scaliger preceded the astronomers in introducing the notion of decimal
    times, designating midnight as .00, 6 a.m. as .25, midday as .50 and 6 p.m.
    as .75, thus allowing easier calculation involving dates and times.
    Astronomers, as noted above, preferred to use .00 to mean midday and .50 to
    mean midnight.

    Modified Julian Day Number
    This was not to the liking of all scholars using the Julian day number
    system, in particular, historians. For chronologists who start "days" at
    midnight, the zero point for the Julian day number system is 00:00 at the
    start of -4712-01-01 J, and this is day 0. This means that 2000-01-01 G is
    2,451,545 JD.
    Since most days within about 150 years of the present have Julian day
    numbers beginning with "24", Julian day numbers within this 300-odd-year
    period can be abbreviated. In 1975 the convention of the modified Julian day
    number was adopted:
    Given a Julian day number JD, the modified Julian day number MJD is defined
    as MJD = JD - 2,400,000.5. This has two purposes:
        Days begin at midnight rather than noon.

        For dates in the period from 1859 to about 2130 only five digits need to
        be used to specify the date rather than seven.
    MJD 0 thus corresponds to JD 2,400,000.5, which is twelve hours after noon
    on JD 2,400,000 = 1858-11-16. Thus MJD 0 designates the midnight of November
    16th/17th, 1858, so day 0 in the system of modified Julian day numbers is
    the day 1858-11-17.

    Lilian Day Number
    This concept is similar to that of the Julian day number. It is named after
    Aloysius Lilius (an advisor to Pope Gregory XIII) who, together with his
    brother, is said to have invented the Gregorian Calendar. The Lilian day
    number is defined as "the number of days since 14 October 1582". This was
    the time of the introduction of the Gregorian Calendar, when it was decreed
    by Pope Gregory XIII that the day following 4 October 1582 (which is 5
    October 1582, in the Julian Calendar) would thenceforth be known as 15
    October 1582. Strictly speaking, the definition should be "the number of
    days since 14 October 1582 in the Proleptic Gregorian Calendar". Thus 15
    October 1582 (Gregorian) is Lilian day 1 (the first day of the Gregorian
    Calendar), 16 October 1582 is Lilian day 2, and so on.
    The relation between Julian day numbers and Lilian day numbers is: LD = JD -
    2,299,160

    Computation
    Mathematicians and programmers have naturally interested themselves in
    mathematical and computational algorithms to convert between Julian day
    numbers and Gregorian dates.
    In 1968 in a letter to the editor of Communications of the ACM (CACM, volume
    11, number 10, October 1968, p.657) Henry F. Fliegel and Thomas C. Van
    Flandern presented such an algorithm.
    The Julian day (jd) is computed from Gregorian day, month and year (d, m, y)
    as follows:
     jd = ( 1461 * ( y + 4800 + ( m - 14 ) / 12 ) ) / 4 +
          ( 367 * ( m - 2 - 12 * ( ( m - 14 ) / 12 ) ) ) / 12 -
          ( 3 * ( ( y + 4900 + ( m - 14 ) / 12 ) / 100 ) ) / 4 +
          d - 32075
    Division is to be understood as in integer arithmetic, with the remainders
    discarded.
    Converting from the Julian day to the Gregorian day is performed thus:
        l = jd + 68569
        n = ( 4 * l ) / 146097
        l = l - ( 146097 * n + 3 ) / 4
        i = ( 4000 * ( l + 1 ) ) / 1461001     (that's 1,461,001)
        l = l - ( 1461 * i ) / 4 + 31
        j = ( 80 * l ) / 2447
        d = l - ( 2447 * j ) / 80
        l = j / 11
        m = j + 2 - ( 12 * l )
        y = 100 * ( n - 49 ) + i + l           (that's a lower-case L)
    Days are integer values in the range 1-31, months are integers in the range
    1-12, and years are positive or negative integers. This algorithm is valid
    only for dates from -4900-03-01 G onward when converting from a Julian day
    number to a date, or from -4800-03-01 G onward (when converting from a date
    to a Julian day number). It should be noted that these algorithms are valid
    only in the Gregorian Calendar and the Proleptic Gregorian Calendar (after
    the dates given above). They do not handle dates in the Julian Calendar.
    This algorithm is implemented in two C functions in DATLIB, a library of C
    functions for converting and manipulating calendar dates.
    A completely different calendar date / Julian day number computational
    algorithm (developed by the present writer) is implemented as two other C
    functions in the same function library. This algorithm handles dates in the
    Julian Calendar as well as dates in the Gregorian Calendar. In addition it
    is valid for any calendar date with a year within the range of about
    -5,800,000 to about +5,800,000.
    In each of these algorithms Julian day number 0 corresponds to -4713-11-24 G
    (= -4712-01-01 J).

knud van eeden

unread,
Jul 5, 2025, 11:34:35 AM7/5/25
to sem...@googlegroups.com
Yes, interesting, I will also check those out later.

Julias Ceasar one day stopped the calendar changes to align, as e g. the start of the harvest had gone out of hand as it did not align at all anymore.
That was thus the start of the Julian calendar.

Pope Gregorius then introduced a new calendar calculation including leap years and 365.25 days in a year thus.
That is the one we are using now, the Gregorian calendar.

Jose Adriano Baltieri was thus asking some days ago for date algorithms implemented in TSE SAL.

As one can see there are a lot of floating point operations in the formulas below. 

TSE had before out of the box only integer operations, no floating point at all thus.

But now floating points calculations are possible 'out of the box' via a TSE program installed then via PowerShell thus that I created some days ago. So implementing the floating point algorithms again now I would probably do differently thus.

Of course other methods running externally and extra to install to install 3rd party programs (.exe, C++ compiled, interpreters, ...) are also possible, but most  will not run also on Linux out of the box also, so at least 2 different versions would be necessary). 

I had at the time also to find a solution of how to implement these floating point operations using integers and integer operations only. 
But that worked out thus somehow.

Here actually below is stated that one can discard fractions in the floating point calculations results, so that only integer operations are enough to do.


Sent from Yahoo Mail on Samsung Galaxy S24 Ultra / 1 terabyte / artificial intelligence

Reply all
Reply to author
Forward
0 new messages