Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • subtracting dates with minutes in them

    Hi,

    I have dates that look like: 30mar2022 08:29:59 for two variables reldate and comdate. I want to gen a variable that is reldate-comdate but I keep getting weird things. Does anyone know? Thanks --CJ


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double(reldate comdate)
    1964248199999.9998 1963938600000.0002
    1960446900000.0002 1959743160000.0002
         1974705960000 1974068279999.9998
         1951060860000      1.9509315e+12
    1962806520000.0002      1931442480000
    1946741579999.9998 1946490840000.0002
         1979282460000      1978556520000
         1.9796271e+12 1979423880000.0002
    1934046359999.9998      1933809240000
    1948802580000.0002 1947928200000.0002
    1974706020000.0002 1974498359999.9998
    1953048360000.0002      1952687040000
    1935050700000.0002 1934599679999.9998
    1969721459999.9998 1969677539999.9998
    1955603759999.9998 1922268239999.9998
    1980239519999.9998 1964189579999.9998
         1947835740000      1946109660000
         1946629380000      1946563620000
    1934094720000.0002      1933758120000
         1952428020000 1952097960000.0002
         1976952540000 1974273420000.0002
    1931022300000.0002 1926179700000.0002
    1978250039999.9998 1969007699999.9998
    1936544220000.0002      1924768260000
                     . 1976483940000.0002
    1939365720000.0002 1939047539999.9998
         1969807020000      1937665380000
    1966685159999.9998 1966537799999.9998
    1949220900000.0002 1947957179999.9998
    1951758300000.0002      1950926280000
    1927279799999.9998      1.9259106e+12
    1953290760000.0002      1952848080000
    1940343719999.9998 1940301719999.9998
    1971197219999.9998 1970248919999.9998
    1961757360000.0002      1952696340000
                     . 1971767879999.9998
         1943688180000      1943597880000
    1928148059999.9998      1869923220000
         1935825960000 1935299939999.9998
    1948367700000.0002      1.9466223e+12
         1948012020000      1909273380000
    1949416860000.0002      1949161620000
    1959380279999.9998 1959331620000.0002
    1932165180000.0002 1932145979999.9998
         1974644220000 1974497999999.9998
    1978248479999.9998      1977454320000
         1.9808064e+12 1966610879999.9998
    1955624940000.0002      1.9555824e+12
         1967104860000      1966756380000
         1960565460000 1960398359999.9998
    1932376380000.0002 1930883519999.9998
         1941955920000      1.9414398e+12
         1947346620000 1946837160000.0002
    1976445659999.9998 1976432640000.0002
    1949926619999.9998      1949158320000
         1970930580000      1.9697628e+12
    1930324619999.9998 1929984180000.0002
    1959754619999.9998 1957092780000.0002
    1939973040000.0002 1939568580000.0002
    1937215740000.0002 1934638020000.0002
         1943204880000 1942586459999.9998
    1975251000000.0002 1975031340000.0002
    1944298679999.9998      1941966540000
    1977323699999.9998 1977236280000.0002
    1949662799999.9998      1947587940000
    1961836319999.9998      1.9615371e+12
    1937726279999.9998 1936428359999.9998
    1953910800000.0002 1953531119999.9998
    1947519959999.9998 1946820780000.0002
    1933347780000.0002 1933299419999.9998
         1946915040000      1946347080000
    1957632059999.9998 1957575300000.0002
         1966672260000 1966392779999.9998
         1975830720000 1975751100000.0002
    1951734780000.0002 1951188659999.9998
         1956419220000 1955957639999.9998
    1983094920000.0002 1950281099999.9998
         1948643220000      1948062180000
    1962176100000.0002 1959783120000.0002
    1973265360000.0002      1973156940000
    1973783999999.9998 1944747659999.9998
    1935306719999.9998 1934638859999.9998
    1964265120000.0002 1963875900000.0002
    1946713799999.9998 1946540639999.9998
    1972632659999.9998 1971598140000.0002
    1979287500000.0002 1975246980000.0002
    1926093359999.9998      1926000660000
    1943204999999.9998 1942015560000.0002
         1.9509423e+12 1950795180000.0002
         1960198620000 1959967319999.9998
         1959957180000 1959520800000.0002
    1970116380000.0002      1965465360000
    1971506759999.9998      1970983020000
         1954515540000 1954402079999.9998
    1978338539999.9998 1976600339999.9998
         1975239420000 1974965220000.0002
    1946120399999.9998      1945883280000
         1.9598733e+12 1959829200000.0002
         1951721040000 1951434900000.0002
         1935765960000 1934073779999.9998
    end
    format %tc reldate
    format %tc comdate

  • #2
    You have not just minutes there but also hours, seconds and milliseconds in there.

    The difference between daily dates is

    Code:
    gen wanted = dofc(reldate) - dofc(comdate)
    and is not itself a date but a duration in days. For more, see

    Code:
    help datetime

    Comment


    • #3
      Thanks!

      Comment

      Working...
      X