0

I used a great script from CJK with no issue , but not sure what happen, recently I noticed some invalid result :

startDate = "2019-05-31" (US Format) Then converted to "31-05-2019"

MyDate (now) = 01-06-2019

Result 31 days

    set creationDate to "2019-05-31"
    set [YearValCreation, MonthValCreation, dayValCreation] to the words of creationDate
    tell (current date) to set startDate to dayValCreation & "-" & MonthValCreation & "-" & YearValCreation --->>> "31-05-2019"

    set MyDate to short date string of (current date) --->>> "01/06/2019"
    set [dayVal, MonthVal, YearVal] to the words of MyDate
    tell (current date) to set MyDate to dayVal & "-" & MonthVal & "-" & YearVal ---->>>> "01-06-2019"
    set DateText to ""
    on timeInterval from startDate to endDate by units : 1
        tell (current date) to set [startDate, ¬
            day, [day, its month, year]] to ¬
            [it, 1, words of startDate]

        tell (current date) to set [endDate, ¬
            day, [day, its month, year]] to ¬
            [it, 1, words of endDate]

        (endDate - startDate) / units
    end timeInterval

    set dayResult to timeInterval from startDate to MyDate by days
    set dayResult to (round (dayResult * 1)) / 1 as integer
--->>> 31

Just release if the date is 30-05-2019 instead of 31-05-2019 I have a correct result

1

It's because you are supplying dates in the format dd-mm-yyyy, where you need to be supplying them in the format yyyy-mm-dd. So your creationDate was already in the correct format before your script adjusted it.

There's no need to replace slashes with hyphens—the handler is, for the most part, indifferent to the delimiter being used (notable exceptions include "." and "+").

  • Yes but the second date is on this format dd-mm-yyyy so I need to convert one of them right? – Kevin Jun 1 at 10:13
  • 1
    Correct. They both ought to be formatted into yyyy-mm-dd. – CJK Jun 1 at 10:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .