Still need help for dates

my AppleScript is still having trouble providing dates to me, in the way I am wanting them.


I would like to do the following:


set the_date to current date "mm/dd/yy"


But I keep getting the full date Friday, January 18, 2019 at 3:08:50 PM


My goal is to put the date with a shortcut into Automator and just have an easy way to enter the date in this format: 01/17/2019


Not possible??


MacBook Air (2018 or later)

Posted on Jan 18, 2019 3:21 PM

Reply
1 reply

Jan 18, 2019 8:12 PM in response to Sheppad

I have finally figured out the solution to my date issue.


I got an idea from this board, got one from a book, then trial and error.


Here is the code:


on run {input, parameters}


tell application "Numbers"


set the_date to current date

set mmo to month of (the_date) as integer

set dda to day of (the_date) as integer


if (mmo) < 10 then

mmo = (mmo)

set mmo to (text of ("0" & mmo))

end if


if (dda) < 10 then

set dda to (text of ("0" & dda))

end if

activate


tell table 1 of the active sheet of document 1 to set the value of cell 1 of the selection range to (mmo & "/" & dda & "/" & year of the_date as string)

end tell

return input

end run


Basically, I am using the month day and year functions for date. I set a variable mmo for month. I look at month, to see if it is a single digit month and if so, put a 0 in front of it. Same with date.


Then I assemble the parts back together.


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Still need help for dates

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.