Page 1 of 1

put the short date + 365 into fld "expire"

Posted: Sat Jul 09, 2011 8:25 pm
by herbwords
Anyone know how to write this correctly?

put the short date + 365 into fld "expire"

The idea is to show the date 1 year from today in field "expire"

Thx,

Patrick

Re: put the short date + 365 into fld "expire"

Posted: Sat Jul 09, 2011 8:40 pm
by dunbarx
Check out the dictionary: "dateItems". Remember to "convert"...

Play around a bit. See that you can add numbers to the several items in what that keyword holds, and you will soon see where to add 365 (or, maybe, "1" ?). Work it until you get the data for one year hence.

Write back if you just want the answer, but this way is much better.

Craig Newman

Re: put the short date + 365 into fld "expire"

Posted: Sun Jul 10, 2011 12:01 am
by herbwords
Hi Craig,

I have looked up all the items on date in the dictionary. It offers a real good explanation of what the commands are and very succint examples of how to use them. However there are no examples that pertain to this situation. I have also gone over the examples in the Resource center and again I have found nothing. It would be great if there were several real life examples of these features but I guess that takes time.
If you know how to write this I would appreciate the example and add it to my book of solutions.

Thanks,

Patrick

Re: put the short date + 365 into fld "expire"

Posted: Sun Jul 10, 2011 1:55 am
by SparkOut

Code: Select all

put the date into myDate
convert myDate to dateItems
myDate now contains a comma delimited list of date items, the first of which is the year.That much information is provided in the dictionary for dateItems.

Code: Select all

add 1 to item 1 of myDate
myDate now contains date items for 1 year hence

Code: Select all

convert myDate to short date
myDate now contains a short date format for the date one year from now.

Craig said "remember to convert" - obviously you didn't realise that "convert" is a keyword that you should also look up in the dictionary. It has a lot of information about exactly this type of date conversion and manipulation. Also be aware of the "useSystemDate" property in case you have users where the usual short date format is not MM/DD/YY order.

Re: put the short date + 365 into fld "expire"

Posted: Sun Jul 10, 2011 3:19 am
by herbwords
Dear SparkOut,

Thank you for taking the time to enlighten me. There are 2 things that are obvious to me. Craig didn't say look up "convert" and there's no such thing as a dumb question.

Again, thanks for your time,

Patrick Edgmon

Re: put the short date + 365 into fld "expire"

Posted: Sun Jul 10, 2011 4:07 am
by dunbarx
Spot on about the dumb question thing. You will be amazed at what comes out of simple discussions.

Perhaps I was too smug and cute about the style of my post. i like new users to learn how to do, not just be fed a three line script. So I put both "dateItems" and "convert" into play, hoping you would understand where to look, to research even, experiment, and start having fun. I still hope you play with these tools. See if you can get yesterday.

Craig Newman

Re: put the short date + 365 into fld "expire"

Posted: Sun Jul 10, 2011 3:30 pm
by herbwords
Craig,

You have succeeded! I have a nice little txt file now that has "date" as the subject. I now understand what the dictionary was saying about dateItems. It made no sense till you wrote this script and I could see it being used in a real example! One thing would have really been the icing on the cake was the final use written to work.

on mouseUp
doDate
end mouseUp

on doDate
put the date into myDate
convert myDate to dateItems
add 1 to item 1 of myDate
convert myDate to short date
put myDate into tDate
put tDate into fld "exDate"
end doDate

Someone should write a book with little examples like this and short explanation of what it does. It would be a best seller! For some reason I keep thinking the old HyperCard stuff had great examples like this. They made me experiment and do some really neat things.

Take Care my friend,

Patrick

Re: put the short date + 365 into fld "expire"

Posted: Sun Jul 10, 2011 4:19 pm
by SparkOut
Glad you are getting there. Just a little point - there is no reason at all to copy the variable "myDate" to another variable "tDate" before showing it in the field. There is nothing special about the variable name "myDate" - it could just as easily have been "tDate" - and probably should.