Re: Conversion of ISO Date String to AppleScript Date
Re: Conversion of ISO Date String to AppleScript Date
- Subject: Re: Conversion of ISO Date String to AppleScript Date
- From: Shane Stanley <email@hidden>
- Date: Sun, 05 Mar 2017 16:58:43 +1100
Here's the problem in a nutshell:
set myDate to date "Tuesday, 31 January 2017 at 12:00:00 am" set month of myDate to 2 return myDate --> date "Friday, 3 March 2017 at 12:00:00 am"
When you set the month to 2, there aren't 31 days in February, so it it rolls the date over to the next month by however many days there are in excess. The easiest solution is to set the day to 1 (or any number less than 29) before setting the month. So this change to your script:
set {day of myDate, year of myDate, month of myDate, day of myDate, hours of myDate, minutes of myDate, seconds of myDate} to {1, theYear as integer, theMonth as integer, theDay as integer, theHour as integer, theMin as integer, theSec as integer}
It's a simple problem when you know about it -- and I the first time I got caught it was painful, so it's not something I forget. But it's a good example of why using code designed to do what you want, rather than rolling your own, is often the safest thing to do.
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden