Working with Dates in differnt Formats

I am working with applescript to help me find out how many days late from today from a text format date of “1/15/2003” how would I go about this? :?

I have tried

set day_late to (current date) - "1/15/2003"

nothing.

Any help would be appreciated!

I think you need a coercition :


set elapsedTime to (current date) - ("'01/01/2003" as date)

That wouldn’t coerce for me (even without the typo), but this does. This should return the number of days.

set dayLate to round (((current date) - (date "1/15/2003")) / (60 * 60 * 24))

-- Delete the following after testing --

if dayLate is 1 then
	display dialog "You are " & dayLate & " day late!" buttons {"Not Bad"} default button 1
end if
if dayLate is greater than 1 then
	display dialog "You are " & dayLate & " days late!" buttons {"Yikes!"} default button 1
end if
if dayLate is 0 then
	display dialog "You aren't late!" buttons {"Excellent!"} default button 1
end if

Yes I just saw that it is not working :cry: but I cannot either run your code there is an error on date “1/15/2003” :cry: :cry:

I wonder if it’s a language issue. Settings in the International preference panel likely have some impact too.

Thanks Rob again for your knowledge base! You are the great helper!

Back to code… :slight_smile: I love my applescript!

:lol:

In Jaguar, it’s in System Preferences. It’s name is “International” and it controls various settings for language, date, time, numbers, etc.

And now I know where my International Control Panel is! That as really kewl Rob. Thanks again!

Using this code works great in applescript

but when I collect the date in a variable it goes into to error.

How do I work myself around this problem…

Does this work? (It does on my machine.)

set theDate to date "01/15/2003"
set dayLate to round (((current date) - (theDate)) / (60 * 60 * 24))

So does this:

set dd to display dialog "Enter a date:" default answer "01/15/2003"
set theDate to date (text returned of dd)
set dayLate to round (((current date) - (theDate)) / (60 * 60 * 24))
display dialog "" & dayLate & " days late."

I collected data from a database then text item delimited it.
To make it work I had to

set theDate to date "01/15/2003" as date

to make this work… strange

Rob, all your above scripts worked fine too. but in this case was weird.

Got it solved!
Thanks again!