• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Number of days left in the month
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Number of days left in the month


  • Subject: Re: Number of days left in the month
  • From: "Marc K. Myers" <email@hidden>
  • Date: Wed, 20 Nov 2002 18:59:52 -0500

Date: Wed, 20 Nov 2002 10:21:43 -0700
Subject: Number of days left in the month
From: Michelle Steiner <email@hidden>
To: email@hidden

Someone asked (on the A'script newsgroup) how to figure out how many
days are left in the current month, or how to compute the total number
of days in the current month. I came up with a solution for days left,
but it fails for February in leap years; someone else came up with an
elegant way for total days in the month. Combining the two gets the
following to compute the number of days remaining in a month.

GetDaysInCurrentMonth() is his; the date arithmetic is mine.

--Michelle

set this_month to month of (current date)
set next_Month to (date (this_month as string)) +
((GetDaysInCurrentMonth() * days) as string)
set days_remaining to ((next_Month - (current date)) / (1 * days)) div 1

on GetDaysInCurrentMonth()
set s to "31"
try
date s
return s
end try
set s to "30"
try
date s
return s
end try
set s to "29"
try
date s
return s
end try
return "28"
end GetDaysInCurrentMonth

A while back I came up with a similar but slightly more compact way of calculating the remaining days:

set theDiff to ((((date daysRemaining()) + days) - (current date)) / days) div 1

on daysRemaining()
set lastDay to {"31", "30", "29", "28"}
repeat with i in lastDay
try
date i
return i
end try
end repeat
end daysRemaining

Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074

[11/20/02 6:58:39 PM]
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Number of days left in the month
      • From: Paul Skinner <email@hidden>
    • Re: Number of days left in the month
      • From: Emmanuel <email@hidden>
  • Prev by Date: Re: illustrator: deleting invisible layers?
  • Next by Date: Re: Launch command in OS X 10.2
  • Previous by thread: Re: Number of days left in the month
  • Next by thread: Re: Number of days left in the month
  • Index(es):
    • Date
    • Thread