|
|
#1 |
|
Major Leaguer
Join Date: Mar 2006
Posts: 280
|
Various dates to date
I have lots of dates like these:
July 7, 2010 7. 31. 2011 tuesday, june 10th, 2010 ... My AppleScript needs to be able to convert date, which is written in any format to yymmdd format. How i can do this? Thanks |
|
|
|
|
|
#2 |
|
League Commissioner
Join Date: Sep 2003
Location: Tokyo
Posts: 6,045
|
PHP has a strtotime() function that works very well - you could set something up with a `do shell script ... ` line.
|
|
|
|
|
|
#3 | |||||||||||||||||||||||
|
Major Leaguer
Join Date: Mar 2006
Posts: 280
|
I did not know that PHP can be run like this. I know nothing about PHP. This works, but how i need to change strtotime row, so it converts dates? do shell script "php -q " & quoted form of POSIX path of "/Users/Hisara/Desktop/date.txt" date.txt: <?php date_default_timezone_set('Europe/London'); echo strtotime("now"), "\n"; ?> And how i can have multiple lines of code without using external txt file? This fails: do shell script "php -q date_default_timezone_set('Europe/London'); echo strtotime("now"), "\n";" Thanks |
|||||||||||||||||||||||
|
|
|
|
|
#4 |
|
Hall of Famer
Join Date: Oct 2002
Location: Halifax, Canada
Posts: 4,945
|
If you'd prefer plain vanilla AppleScript then this works if the dates don't include things like "10th" or "3rd". Of course those could be filtered out if your dates do:
Code:
set tDates to {"July 7, 2010", "7. 31. 2011", "tuesday, june 10, 2010"}
set Reslt to {}
repeat with aDate in tDates
set someDate to date aDate
set {year:y, month:m, day:d} to (someDate)
set end of Reslt to text 3 thru -1 of ((y * 10000 + m * 100 + d) as string)
end repeat
--> {"100707", "110731", "100610"}
__________________
17" MBP, OS X 10.8.3; 27" iMac, OS X 10.8.3 |
|
|
|
|
|
#5 | ||||||||||||||||||||||||||||||||||||||||||
|
League Commissioner
Join Date: Sep 2003
Location: Tokyo
Posts: 6,045
|
If you want to make a batch file just have PHP read the file directly. fopen() or file_get_contents(); If you prefer to have (almost) everything done via Applescript just put the entire php command on one line. Build it as a string.
That will give you a unixtime integer. Explore the date() function. The line break is optional. |
||||||||||||||||||||||||||||||||||||||||||
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|