Strange date anomaly!!!

Dear All,

I would be really grateful for your help on this matter. I am trying to create a specific date, and followed a link which said that you should make a variable using the current date, and then change the year, month, day, etc. This seems to be fine, except that when I am changing over the month, it is changing into the wrong month. I am inputting 9 for September - I have logged this to check the details, and it is outputting October. I cannot see any reason for this, and I need to get this completed. Is there a better way, and why is this error occurring at all???


			set dateWordsArray to words of theDate
			set returnedDay to item 1 of dateWordsArray
			set returnedMonth to item 2 of dateWordsArray
			if returnedMonth is equal to "January" then
				set returnedMonth to 1
			else if returnedMonth is equal to "February" then
				set returnedMonth to 2
			else if returnedMonth is equal to "March" then
				set returnedMonth to 3
			else if returnedMonth is equal to "April" then
				set returnedMonth to 4
			else if returnedMonth is equal to "May" then
				set returnedMonth to 5
			else if returnedMonth is equal to "June" then
				set returnedMonth to 6
			else if returnedMonth is equal to "July" then
				set returnedMonth to 7
			else if returnedMonth is equal to "August" then
				set returnedMonth to 8
			else if returnedMonth is equal to "September" then
				set returnedMonth to 9
			else if returnedMonth is equal to "October" then
				set returnedMonth to 10
			else if returnedMonth is equal to "November" then
				set returnedMonth to 11
			else if returnedMonth is equal to "December" then
				set returnedMonth to 12
			end if
			
			set returnedYear to item 3 of dateWordsArray
			log returnedMonth
			set year of activeDate to returnedYear
			set month of activeDate to returnedMonth
			log activeDate


The log that is coming back is as follows:

(*9*)
(*date Sunday, 1 October 2017 at 21:46:10*)

Any help would be much appreciated. Kindest regards,

DDHawk

Model: MacBook Pro
AppleScript: 2.9
Browser: Safari 602.3.12
Operating System: Mac OS X (10.10)

There’s one other detail: to be safe, you need to first set the day to 1 (or some other number less than 29) and then set the month, in case the date’s day is one that your required month doesn’t contain.

Dear Shane,

Thank you for that!!! I thought that I was going mad!!! Silly mistake - did not even consider the point!!!

Happy new year and regards,

Chris

Maybe you may try to use :

set theDate to (current date)
tell theDate
	set returnedDay to its day
	set returnedMonth to its month as integer
	set returnedYear to its year
	set returnedTime to its time
end tell
set fake to "12/12/12" # with tis fake value there will be no problem for month crossing and for date format
set activeDate to date (fake)
set year of activeDate to returnedYear
set month of activeDate to returnedMonth
activeDate

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) dimanche 1 janvier 2017 17:09:36