Create new folder with current date unique format (help!)

I am trying to create a new folder in a folder in my desktop. Folder name should just be the current date but in the format YYYY.MM.DD. I cannot get it to work with my current script

tell application "Finder:
	set shortDate to short date string of (current date)
	set yearDate to shortDate's year
	set monthDate to shortDates's month
	set dayDate to shortDate's day
	set folderDate to ((shortDate's year) as text) & "." ((shortDate's month) as text) & "." ((shortDate's day) as text))
	make new folder in folder "NikonImages" with properties {name:folderDate}
end tell

([applescript] and [/applescript] posting tags added by NG.)

Would be better with correct syntax

-- Instructions which have no need to be in the tell "Finder" block
set p2d to path to desktop as text
set shortDate to short date string of (current date)
-- shortDate is a string so it had no property like year, month or day
set curDate to (current date)
set yearDate to curDate's year
if yearDate < 1000 then set yearDate to yearDate + 2000
set monthDate to curDate's month as number -- extract the month as a number of 1 or two digits
set dayDate to curDate's day -- extract a number of one or two digits
set folderDate to (yearDate as string) & "." & text 2 thru 3 of ((100 + monthDate) as string) & "." & text 2 thru 3 of ((100 + dayDate) as string)
-- Only now, you speak to the Finder.
tell application "Finder" -- here was a fatal typo : a colon took the place of the ending quote
	make new folder in folder (p2d & "NikonImages") with properties {name:folderDate}
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 14 avril 2020 22:34:47

That worked! Thank you so much! I spent many hours trying to search for an answer!!

Formatting date strings with padding zeros is quite cumbersome in vanilla AppleScript.

Two alternatives are the shell

set folderDate to do shell script "/bin/date +%Y.%m.%d"

or AppleScriptObjC

set formatter to current application's NSDateFormatter's alloc()'s init()
formatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"en_US_POSIX")
formatter's setDateFormat:"yyyy.MM.dd"
set folderDate to (formatter's stringFromDate:(current date)) as text

I’ve always used the script included below to make a date stamp. It’s similar in many respects to Yvan’s suggestion and was originally derived from a long date/time thread earlier in this forum. The script is reasonably quick, with a first-run time of 4 milliseconds, although it probably breaks in some locales.

set {year:y, month:m, day:d} to (current date)
set theDate to ((y * 10000) + ((m as integer) * 100) + d) as text
set folderDate to text 1 thru 4 of theDate & "." & text 5 thru 6 of theDate & "." & text 7 thru 8 of theDate

In my own scripts I often use:

on dateTimeStamp()
	tell (current date) to return (((its year) * 10000 + (its month) * 100 + (its day)) as text) & "_" & text 2 thru -1 of ((1000000 + (its hours) * 10000 + (its minutes) * 100 + (its seconds)) as text)
	# return (do shell script "date +_%Y%m%d_%H%M%S")
	#return (do shell script "date +_%F_%T")
end dateTimeStamp

I made numerous tests and saw that it’s 22 times faster than the shell script version.

In scripts using ASObjC for other tasks I use the ASObjC code but don’t use such sledgehammer just for formatting a date.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 15 avril 2020 17:53:54