Comparing dates

James Sentman james at sentman.com
Thu Jul 26 08:22:09 EDT 2018


now that I look at this again I wonder that I didn’t just split the text on the ampersand… That would be less code ;) 

property test : "7/22/18 @ 4:21 PM"

set AppleScript's text item delimiters to {"@"}
set parts to date (text item 2 of test & text item 1 of test)
set AppleScript's text item delimiters to {}

return time string of parts


I think I was originally trying to just break it on words but it turns out AppleScript also thinks that the forward slashes in the dates are word boundaries so that didn’t work, but I kept the original thinking of splitting on the spaces instead of the ampersand…

Not that you have to change it now since it’s working ;) Thats fine, but the simplest way to do it is above.

If the date/time strings that are being sent ever change in format you’ll need to update that code to support whatever they are then but until that happens you should be fine.



> On Jul 25, 2018, at 9:30 PM, John Gniewkowski <jgniewkowski at live.com> wrote:
> 
> That worked perfectly! Thanks all!
>  
> From: XTensionList <xtensionlist-bounces at machomeautomation.com <mailto:xtensionlist-bounces at machomeautomation.com>> on behalf of James Sentman <james at sentman.com <mailto:james at sentman.com>>
> Reply-To: XTension Discussion List <xtensionlist at machomeautomation.com <mailto:xtensionlist at machomeautomation.com>>
> Date: Tuesday, July 24, 2018 at 1:36 PM
> To: XTension Discussion List <xtensionlist at machomeautomation.com <mailto:xtensionlist at machomeautomation.com>>
> Subject: Re: Comparing dates
>  
> the problem is that the format of that string is not one that AppleScript knows how to parse out. You’ll have to move some of that around. Basically just removing that “@“ is all i’m doing here.
>  
> property test : "7/22/18 @ 4:21 PM"

Thanks,
 James


James Sentman                       http://www.PlanetaryGear.org		http://MacHomeAutomation.com




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.machomeautomation.com/pipermail/xtensionlist/attachments/20180726/b1aa2ad9/attachment.html>


More information about the XTensionList mailing list