• 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: getting the date
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting the date


  • Subject: Re: getting the date
  • From: Graff <email@hidden>
  • Date: Tue, 30 Dec 2003 23:40:14 -0500

On Dec 30, 2003, at 10:49 PM, Walter Ian Kaye wrote:

At 06:28p -0500 12/30/2003, Graff didst inscribe upon an electronic papyrus:

((b - theDate) div -2500000 + 1 )

Which takes the difference (in seconds) between the current date and and the the same day in January, divides that by 289 days (in seconds) and adds a month. This gives you the current month, roughly. This will probably work fine but I'd worry about it being correct under all circumstances.

OK, but then what makes 289 days so magical?

Sorry, my bad. I must have forgotten a decimal point, that should be approximately 28.9 days. Approximately the average length of a month. Basically the theory is if you divide a number from 0 to 29999999 by 2500000 and cut off the decimal part you will get a number from 0 to 11. Add one to that and it is from 1 to 12, corresponding to the number of month. The only thing is that there are up to approximately 31622400 seconds in a year. However, this technique is saved by the fact that it loses one month worth of seconds since it counts from 1/20 to 12/20 (for example) instead of 1/1 to 12/20. Counting from 1/20 to 12/20 is under 29000000 seconds, a number that works.

It is a rough method but it does work. I would prefer to use a clearer and more precise method but I can't argue with the results of this script. If you want to convert a date quickly and you don't care if people easily understand how it works then this script is for you.

- Ken
_______________________________________________
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.

References: 
 >Re: getting the date (From: Nigel Garvey <email@hidden>)
 >Re: getting the date (From: Walter Ian Kaye <email@hidden>)
 >Re: getting the date (From: Graff <email@hidden>)
 >Re: getting the date (From: Walter Ian Kaye <email@hidden>)

  • Prev by Date: Re: getting the date
  • Next by Date: Re: New AppleScript book (AppleScript: the Definitive Guide!)
  • Previous by thread: Re: getting the date
  • Next by thread: Re: getting the date
  • Index(es):
    • Date
    • Thread