Hi folks,
I am trying to set an expiry date for a demo.
Will this work everywhere in the world?
set lastDay to 15
set lastMonth to 4
set lastYear to 2012
set {day:D, month:M, year:Y} to (current date)
set validDemo to (lastDay ≥ D and lastMonth = M as integer and lastYear = Y)
return validDemo --> true until the 15th of April of this year, then false
Yes, it does.
You can also do it by comparing date objects directly
set lastDay to 15
set lastMonth to 4
set lastYear to 2012
set expireDate to (current date)
tell expireDate to set {day, year, its month, day} to {1, lastYear, lastMonth, lastDay}
set validDemo to expireDate comes after (current date)
This is the ASOC equivalent
set components to current application's NSDateComponents's alloc's init()
components's setDay_(15)
components's setMonth_(4)
components's setYear_(2012)
set gregorian to current application's NSCalendar's alloc's initWithCalendarIdentifier_(current application's NSGregorianCalendar)
set expireDate to gregorian's dateFromComponents_(components)
set validDemo to current application's NSDate's |date|()'s compare_(expireDate) = current application's NSOrderedAscending
Tahank you Stefan,
Brilliant as usual!