Hoping for some help on this one being new to this software. I am trying to enter in the Date and Time in a text field every time a run a script
I have tried the following:
TypeText " &date"
put date into test
Probably something simple but I have searched the forums and the SenseTalk reference to no avail. Any help would be greatly appreciated.
Do you just want today’s date and the time at the point the script is run?
typeText today's date
typeText now's time
Chapter 13 in the Sensetalk reference talks in great detail about date and time.
looking at the results now.
Or perhaps somewhat more commonly:
TypeText the date
But there are lots of options. As our friend FHQWHGADS said, chapter 13 in the SenseTalk manual will give you more information than you ever wanted to know on the subject…
I swear I read the reference manual
How does one ensure that the returned value is, in the case where the month value is < 10, a two digit value?
The input fields that I have want to see DDMMYYYY values.
put the long date into ThisDate
put (Day of TheDate) & "/" & ( Month of TheDate) & "/" & ( year of TheDate) into ThisDate
repeat with ThisItem = each Item Delimited By "/" of ThisDate
Gives me “7” in the month, rather than “07”, and then I end up with a value along the lines of “14/72/008_”
On a related note
put the long date + 1 year into anotherdate
Doesn’t work, although my reading of the reference manual suggests that it should.
put the long date + 52 weeks into anotherdate
almost works, but comes up one day short. (leap year perhaps?)
Thoughts and clues please?
The day, month, and year functions each return a number (not a formatted string) so using them won’t give you leading zeros for single-digit days or months. It could be done by setting the numberFormat, but for what you want there’s an easier way, using the formattedTime() function. This should do what you want:
TypeText formattedTime("%d%m%Y", TheDate)
The formatting codes that you can use with this function are described in the documentation for the timeFormat global property.
Regarding your other question (adding a year to a date), SenseTalk’s predefined time interval values only go up through weeks, and don’t currently include months and years since they aren’t a consistent number of seconds long. To get a date that’s a year in the future, you can add 365 days, except of course that won’t be correct for leap years.
So to correctly add a calendar year, the best approach is probably to convert to the dateItems format, which separates the date into separate values for year, month, day, and so forth. In this format you can add or subtract any number of years, months, days, etc. by dealing with the appropriate item. Then convert back to the final format that you want, like this:
set myDate to today
convert myDate to dateItems
add 1 to item 1 of myDate -- item 1 is the year
convert myDate to short date -- or whatever format you want
The dateItems formats are often overlooked, but can be quite useful for doing this sort of calculation.
Can anyone help me how to get the system’s time in 24hours format? For example instead of 3:34 PM, I need to get 15:34.
set the clockformat to 24