Eu trabalho com três formatos de data,
1 04/18/2015 (PS minha data do sistema não é a mesma, mas DD / MM / AA)
2 2 de junho de 2012 mas convertido para o 1º formato por código abaixo
3 Sábado, 24 de março de 2018 (data atual)
Acabei de criar o script abaixo para converter as duas datas no mesmo formato:
set creationDate to "March 23rd, 2018"
set CreationDay to ""
set Creationmonth to ""
set Creationyear to ""
if creationDate contains "1st" then
set CreationDay to "1"
end if
if creationDate contains "2nd" then
set CreationDay to "2"
end if
if creationDate contains "3rd" then
set CreationDay to "3"
end if
if creationDate contains "4th" then
set CreationDay to "4"
end if
if creationDate contains "5th" then
set CreationDay to "5"
end if
if creationDate contains "6th" then
set CreationDay to "6"
end if
if creationDate contains "7th" then
set CreationDay to "7"
end if
if creationDate contains "8th" then
set CreationDay to "8"
end if
if creationDate contains "9th" then
set CreationDay to "9"
end if
if creationDate contains "10th" then
set CreationDay to "10"
end if
if creationDate contains "11th" then
set CreationDay to "11"
end if
if creationDate contains "12th" then
set CreationDay to "12"
end if
if creationDate contains "13th" then
set CreationDay to "13"
end if
if creationDate contains "14th" then
set CreationDay to "14"
end if
if creationDate contains "15th" then
set CreationDay to "15"
end if
if creationDate contains "16th" then
set CreationDay to "16"
end if
if creationDate contains "17th" then
set CreationDay to "17"
end if
if creationDate contains "18th" then
set CreationDay to "18"
end if
if creationDate contains "19th" then
set CreationDay to "19"
end if
if creationDate contains "20th" then
set CreationDay to "20"
end if
if creationDate contains "21st" then
set CreationDay to "21"
end if
if creationDate contains "22nd" then
set CreationDay to "22"
end if
if creationDate contains "23rd" then
set CreationDay to "23"
end if
if creationDate contains "24th" then
set CreationDay to "24"
end if
if creationDate contains "25th" then
set CreationDay to "25"
end if
if creationDate contains "26th" then
set CreationDay to "26"
end if
if creationDate contains "27th" then
set CreationDay to "27"
end if
if creationDate contains "28th" then
set CreationDay to "28"
end if
if creationDate contains "29th" then
set CreationDay to "29"
end if
if creationDate contains "30th" then
set CreationDay to "30"
end if
if creationDate contains "31st" then
set CreationDay to "31"
end if
if creationDate contains "2018" then
set Creationyear to "2018"
end if
if creationDate contains "2017" then
set Creationyear to "2017"
end if
if creationDate contains "2016" then
set Creationyear to "2016"
end if
if creationDate contains "2015" then
set Creationyear to "2015"
end if
if creationDate contains "2014" then
set Creationyear to "2014"
end if
if creationDate contains "2013" then
set Creationyear to "2013"
end if
if creationDate contains "2012" then
set Creationyear to "2012"
end if
if creationDate contains "2011" then
set Creationyear to "2011"
end if
if creationDate contains "2010" then
set Creationyear to "2010"
end if
if creationDate contains "2009" then
set Creationyear to "2009"
end if
if creationDate contains "2008" then
set Creationyear to "2008"
end if
if creationDate contains "2007" then
set Creationyear to "2007"
end if
if creationDate contains "2006" then
set Creationyear to "2006"
end if
if creationDate contains "2005" then
set Creationyear to "2005"
end if
if creationDate contains "2004" then
set Creationyear to "2004"
end if
if creationDate contains "2003" then
set Creationyear to "2003"
end if
if creationDate contains "January" then
set Creationmonth to "01"
end if
if creationDate contains "February" then
set Creationmonth to "02"
end if
if creationDate contains "March" then
set Creationmonth to "03"
end if
if creationDate contains "April" then
set Creationmonth to "04"
end if
if creationDate contains "May" then
set Creationmonth to "05"
end if
if creationDate contains "June" then
set Creationmonth to "06"
end if
if creationDate contains "July" then
set Creationmonth to "07"
end if
if creationDate contains "Agust" then
set Creationmonth to "08"
end if
if creationDate contains "September" then
set Creationmonth to "09"
end if
if creationDate contains "October" then
set Creationmonth to "10"
end if
if creationDate contains "November" then
set Creationmonth to "11"
end if
if creationDate contains "December" then
set Creationmonth to "12"
end if
set CreationfinalDate to CreationDay & "/" & Creationmonth & "/" & Creationyear
return CreationfinalDate
Pergunta 1: Como posso converter o número de data 3 (que é a data atual) para o mesmo formato
(Eu sei como retornar como uma corda, mas não o contrário)
set myDate to date string of (current date)
Pergunta 2: posso criar um script para informar se a diferença entre a data 2 e a data 3 está dentro de 60 dias ou fora de 60 dias?
fonte
Coerce sua data em um AppleScript
date
objeto, então você pode executar cálculos comoset myNewDate to myDate + (2 * days)
. Para mais cálculos de data, consulte Cálculos de data / hora usando o AppleScript e Guia da Linguagem AppleScript - Data .Abaixo está uma abordagem alternativa para analisar o terceiro formato de data, mais detalhado. Essa abordagem usa sub-rotinas para dividir e aparar a entrada. Não está completo, mas espero que seja útil:
fonte