Time Commands & Repeat

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

bigred
Newbie
Posts: 10
Joined: Fri Jul 16, 2004 7:50 am

Time Commands & Repeat

Post by bigred » Fri Jul 23, 2004 10:26 am

Normally if the time is 9, it shows a 0 in front of the number. Is there a way to truncate that 0 and just have the single digit? For example if its 3o'clock, the output shows "03", I want it to just show "3".
Also is there a way to have it display the time in a 12 hour clock? And add AM/PM after the number?

EDIT: I used this code and it solved the above two problems, but caused a new one.
GetTime>time
Let>msg=The Time Is :
ConCat>msg,time
Message>msg
That worked, but it displays the seconds, and it can't do that. Anyway to remove that?


My other question is how do I get the script to repeat its self? Once it has reached the end I want to script to start at the top again, and do so for a set number of times.

Lumumba

Post by Lumumba » Fri Jul 23, 2004 11:11 am

Hour>hh
Let>hh=%hh%/1
MessageModal>%hh%

I guess the values of time/date vars are assigned to your regional settings. Check this out.

Lumumba

Post by Lumumba » Fri Jul 23, 2004 11:18 am

Repeat>variable

Use in conjunction with Until. Iterates the code from the Repeat statement to the Until statement until the specified variable equals the value specified in the Until statement.

See also : Until

Example

GetFileList>c:\temp\*.*,files
Separate>files,;,file_names
MessageModal>Num Files: %file_names_count%

Let>k=0
Repeat>k
Let>k=k+1
Message>file_names_%k%
Until>k,file_names_count

bigred
Newbie
Posts: 10
Joined: Fri Jul 16, 2004 7:50 am

Post by bigred » Fri Jul 23, 2004 11:34 am

1) Ok cool, thanks. But I have a question, am I write in guessing that you are just removing the first digit from the hour variable? What would this code do if the time was "12"?
Also what does "/1" do? I understand all of your other code, except that part.

EDIT: I just noticed that the "Hour>" command grabs the time in a 24 hour format. I know thats the norm in most places, but in North America we use the 12hour clock. Any way to do that trick and use the 12hour system? Also I noticed that if I swapped the "/1" for a "+5" not only did it add 5 to whatever the current hour was, but it also removed the preceding 0, if there was one. Could anyone explain whats going on here? I'm lost.

You're right, if I edit my regional settings I can remove the seconds, and even make AM/PM lower case (which I also wanted to do). Its not probable that I will be able to edit the Regional Settings on every system that may run my script. So is there also a way to convert the AM/PM to lowercase, and remove the seconds?


2) Yeah I had looked at that example in the help file originally and didn't understand it at all, but now I've got it working. :)

Lumumba

Post by Lumumba » Fri Jul 23, 2004 4:38 pm

/1
Stolen from the manual (aka "your friend")

--------------------------
Let>A=60-4 --> sub

Let>A=5*3 --> mult

Let>F=75/32 --> div

Let>F=12+88 --> add
--------------------------

So 03 divided over 1 = 3

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Fri Jul 23, 2004 9:07 pm

Depending on what you are doing, changing your system settings may solve your problem of leading zeros also. And no script required!

Control Panel, Regional Settings, tab for Time, set the Time Style to h:mm:ss tt
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

bigred
Newbie
Posts: 10
Joined: Fri Jul 16, 2004 7:50 am

Post by bigred » Sat Jul 24, 2004 12:27 am

Lumumba wrote:Stolen from the manual (aka "your friend")
So 03 divided over 1 = 3
Oh ok. Yeah I read that in the help file, but at 4am I told myself that a number divided by one doesn't do anything.

But is there a way to get a non 24hour time? Far as I can tell the "Hour>" command is 24 hour only... "GetTime>" is 12hour for me since my computers settings are that way, but it also displays seconds, and AM/PM in uppercase. Is there anyways to use 12 hour time, with just the Hours, Minutes and lowercase am/pm?



Thanks Bob, we already went over that..

Lumumba

Post by Lumumba » Sat Jul 24, 2004 8:11 am

// MidStr>string,start,length,result

Let>string=2004/07/23 01:59:59 AM
MidStr>%string%,1,10,Date
MessageModal>%Date% //Test

MidStr>%string%,12,2,Hour
MessageModal>%Hour% //Test

MidStr>%string%,21,1,AMPM
MessageModal>%AMPM% //Test

If>AMPM=A, Goto, AnteMeridiem

Label>PostMeridiem
Let>AMPM=pm
Goto>Chronos

Label>AnteMeridiem
Let>AMPM=am

Label>Chronos
MessageModal>%Hour%/%AMPM%

------

Have a look at VBScript !
Or a scripting tool which provides date/time conversion in his command reference.

Lumumba

Post by Lumumba » Sat Jul 24, 2004 8:28 am

[t345.zip] (29k)


[quote] INSTRUCTIONS FOR T
Copyright (c) 1992-2000 by Tony G. Papadimitriou

Hi,

This program is a very simple utility to display the current day, date, and
time, or, should you supply a parameter (or more) the day, and date of the
effective date as modified by the parameter. It's assumed your computer
clock is set and working properly. If your computer does not have a hardware
clock, you should use the DOS commands DATE and TIME to set the DOS software
clock at startup or anytime before running this program. Place this program
on a directory that's part of your path (something like C:\UTIL or C:\UTILS)
for easier access at any time.

Some usage examples follow:

C:\>t
Sunday, 9 October, 1994 8:25 pm 282- 83 [41] 0 0. 0. 0

C:\>t 30
Tuesday, 8 November, 1994 8:25 pm 312- 53 [45] 30 0. 0.30

C:\>t -100
Friday, 1 July, 1994 8:25 pm 182-183 [26] -100 0. 3. 8

C:\>t 1/
Saturday, 1 October, 1994 8:25 pm 274- 91 [40] -8 0. 0. 8

C:\>t 1/1
Saturday, 1 January, 1994 8:25 pm 1-364 [ 1] -281 0. 9. 8

C:\>t 1/1/2
Wednesday, 1 January, 1992 8:25 pm 1-365 [ 1] -1012 2. 9. 8

C:\>t 1/1/82
Friday, 1 January, 1982 8:25 pm 1-364 [ 1] -4664 12. 9. 8

C:\>t -4648
Sunday, 17 January, 1982 8:25 pm 17-348 [ 3] -4648 12. 8.23

C:\>t //2000
Monday, 9 October, 2000 8:25 pm 283- 83 [41] 2192 6. 0. 0

C:\>t 1-1-2082
Thursday, 1 January, 2082 8:25 pm 1-364 [ 1] 31861 87. 2.23

C:\>t 1 2 3 @1/1/90 1 2 3
Monday, 10 October, 1994 8:25 pm 283- 82 [41] 1 0. 0. 1
Tuesday, 11 October, 1994 8:25 pm 284- 81 [41] 2 0. 0. 2
Wednesday, 12 October, 1994 8:25 pm 285- 80 [41] 3 0. 0. 3
Monday, 1 January, 1990 8:25 pm 1-364 [ 1] 0 0. 0. 0
Tuesday, 2 January, 1990 8:25 pm 2-363 [ 1] 1 0. 0. 1
Wednesday, 3 January, 1990 8:25 pm 3-362 [ 1] 2 0. 0. 2
Thursday, 4 January, 1990 8:25 pm 4-361 [ 1] 3 0. 0. 3

C:\>t -3 -2 -1 0 1 2 3 ?
Thursday, 6 October, 1994 8:25 pm 279- 86 [40] -3 0. 0. 3
Friday, 7 October, 1994 8:25 pm 280- 85 [40] -2 0. 0. 2
Saturday, 8 October, 1994 8:25 pm 281- 84 [41] -1 0. 0. 1
Sunday, 9 October, 1994 8:25 pm 282- 83 [41] 0 0. 0. 0
Monday, 10 October, 1994 8:25 pm 283- 82 [41] 1 0. 0. 1
Tuesday, 11 October, 1994 8:25 pm 284- 81 [41] 2 0. 0. 2
Wednesday, 12 October, 1994 8:25 pm 285- 80 [41] 3 0. 0. 3

The numbers following the time show: the day number of the year, the number
of days remaining to the end of the year, the week number in the year, and
the number of days since today (or the effective date). A negative means
past while a positive means future. That's in case you supply a parameter,
otherwise, this number is zero because the difference in days from now is
zero. What follows is a number of the form yy.mm.dd which refers to the
years, months, and days between the current date and the computed date in
case of parameters.

You can set the current date of the clock (only for the purposes of this
program, changes won't become permanent) in order to calculate date
differences between two or more dates that are different from the actual
current date. You do this by using the @ (or !) date prefix such as @1/1/80
or !1/1/80. The ! behaves like the @ with the only difference that it does
not show the effective date entered.

Therefore, the command t !1/1/80 2/3/92 will produce the output:

Monday, 2 March, 1992 8:21 pm 62-304 [ 9] 4444 12. 2. 1

The 12.2.1 means that March 2, 1992 is 12 years, 2 months, and 1 day away
from January 1, 1980. The 1/1/80 date did not show because of the ! prefix,
a @would have shown the following:

Tuesday, 1 January, 1980 8:21 pm 1-365 [ 1] 0 0. 0. 0
Monday, 2 March, 1992 8:21 pm 62-304 [ 9] 4444 12. 2. 1

Assuming your birthday was on July 4, 1960 the command T !4/7/60 / will show
the current date with a number of days and yy.mm.dd that will be your age
today, eg.,

C:\>t !4/7/60 /
Sunday, 9 October, 1994 8:32 pm 282- 83 [41] 12515 34. 3. 5

while T !4/7/60 1/1/2000 will show that person's age on January 1, 2000.

C:\>t !4/7/60 1/1/2000
Saturday, 1 January, 2000 8:39 pm 1-365 [ 1] 14425 39. 5.28

Those in countries that use a MM/DD/YY format should be careful to remember to
enter dates in European format, i.e., DD/MM/YY Obvious mistakes, such as a
month over 12 or a day over 31 will cause an error but many dates in the wrong
format cannot be detected.

End of the month dates that don't actually exist will produce a date in the
following month, e.g., T 30/2/94 will show:

Wednesday, 2 March, 1994 8:42 pm 61-304 [ 9] -221 0. 7. 7

because February 1994 had only 28 days, so you're shown the date two days
(30-28) after the last day in February 1994. You can use this (with a
29/2/YY date, for any value of YY) to detect if a year was or will be a leap
year. If you get a February date, you got a leap year, but if you get March
1, it's not a leap year.

You can enter years in YYYY format if you refer to a different century than
the one indicated by the clock's current date, YY if referring to same
century but different decade, and Y if referring to same decade but different
year. You omit whatever part of the date is the same as the current date,
however, you must maintain the delimiters (/ or - or .). So, for example, //3
means same day, same month, same decade in year ending with 3. Today can be
written as / or . but not - because - in the beginning of a parameters
expects it to be a negative number of days by which to offset the current
date. If you only enter the day part (first part) of a date you must follow
it by a delimiter in order to differentiate between a positive number of days
offset and the actual number in the month.

With this newer version, you can also create a notes file for use with T.EXE
that will allow you to see one or more comments for whatever date matches the
T parameters. To setup T.EXE for using a notes file, first create the file
(in plain-ASCII format, example follows), then give the command: T SETUP
where is the full path of the ASCII notes file.

By default, you can use a notes file if you put a file named T.DAT in
the same directory where the program T.EXE is located.

A sample of such a file follows between the dotted lines:

---------------------------------------------------------------------
1.1 Happy New Year
8.8.1920 Birth of someone special
4.7 4th of July
25.12 Christmas Day
1. A new month begins
.2 Every day in February
---------------------------------------------------------------------

Dates without the year element will display each year. Dates without the
month and year element will display each month. Dates without the day and
year will display each day of the month. And so, on.

T_GRK.EXE is the same program in the Greek language. Rename to T.EXE
if you want the Greek version.

I hope you find it useful!

ÉÃÂ

bigred
Newbie
Posts: 10
Joined: Fri Jul 16, 2004 7:50 am

Post by bigred » Sat Jul 24, 2004 10:50 am

Lumumba wrote:// MidStr>string,start,length,result
...
...
------
Have a look at VBScript !
Or a scripting tool which provides date/time conversion in his command reference.
I tried to use your code, but it gave me an error. Also without an explaination I am having trouble understanding how to use it.

I've thought about learning VBS, but I don't really have the time. Thats why I wanted to use a macro program. If I did learn some VBS, would it let me do everything I want?
On a side note, can regular VB, do mouse clicks, and move windws by their name, etc? I know M/S can use VBS, but can it also use straight VB code?

Also what do you mean about another scripting tool. Do you mean another Macro Program?

---------------

I downloaded the program you linked. I understand that it outputs the date, but what does that do for me? I appreciate the help, and the example code, but without comments, and instructions I'm lost.

Lumumba

Post by Lumumba » Sat Jul 24, 2004 1:17 pm

Well, have you checked about a trailing space character at each line of the code (after you copied it from the forum) ?

It's a standard to check for those to remove them, otherwise the code won't work !
// Set the variable string with the value 2004/07/23 01:59:59 AM
Let>string=2004/07/23 01:59:59 AM
// read 10 characters beginning at position 1 of the string and set the output as value of the variable Date
MidStr>%string%,1,10,Date
//Display the content of variable Date
MessageModal>%Date%

//See above
MidStr>%string%,12,2,Hour
MessageModal>%Hour%

//The same as above
MidStr>%string%,21,1,AMPM
MessageModal>%AMPM%

//If the variable AMPM has the value a goto the Label/section AnteMeridiem (that's latin :wink:)
If>AMPM=A, Goto, AnteMeridiem

//Replace the current value (P) of the variable AMPM with its lower case equivalent (pm)
Label>PostMeridiem
Let>AMPM=pm
Goto>Chronos

//Replace the current value (a) of the variable AMPM with its lower case equivalent (am)
Label>AnteMeridiem
Let>AMPM=am

Label>Chronos
MessageModal>%Hour%/%AMPM%
-----
Can VB do everthing M/S can do and more?
You can combine MSched with VBS to get the best of both worlds.
If I did learn some VB, would it let me do everything I want?
Even if you want to climb up the Mount Everest - naked :lol:. TBH - I don't know everything you wanna do ...
Also what do you mean about another scripting tool. Do you mean another Macro Program?
Yep. ScriptIt/RunCMD/VBScript/AutoHotkey/AutoIt3/Profan/...
It makes no difference which one you prefer/start with. Just do it :D

-----
I understand that it outputs the date, but what does that do for me
That's it. It outputs the date for you, in the format you prefer.
Sunday, 9 October, 1994 8:25 pm 282- 83 [41] 0 0. 0. 0


//Run t.exe and pipe its output to a file
Run Program>CMD /C C:\t.exe > C:\DateTime.txt
//Check the output file for the line number and use it in the following command
ReadLn>C:\DateTime.txt,1,Line
//Separator should be the space character
Separate>Line, , DateComponents
//Display the content of the fifth field (maybe it's the 4. or 6. ?)
MessageModal>%DateComponents_5%
//Check the output file used to get the line
ExecuteFile>C:\DateTime.txt


This script is untested ! :oops:

Guest

Post by Guest » Sat Jul 24, 2004 2:31 pm

I feel very dumb... I still can't get your script to work. :oops:
I get the following message windows:
- 2004/07/23
- 01
- A

Then an error message that says, "Error - Subroutine/Label Goto Not Found!"

Also, at the start of the script you set the variable "string" with a static date and time. Is it possible to use the command "GetTime>" instead? That way every time I run the script it will automatically get the current time, then reformat it, then output it.

----------

With that time program it generates the text in a DOS window, so how do I use the text it outputs?

bigred
Newbie
Posts: 10
Joined: Fri Jul 16, 2004 7:50 am

Post by bigred » Sat Jul 24, 2004 2:35 pm

Err, disregard that last sentence in the above post about how to use the t.exe program. I wrote that 2 messages ago, and did not mean to post it.

----------

EDIT: Ok I think I've got it!! :D Does this code look ok?
GetTime>Time
MidStr>%Time%,1,2,Hour
Let>Hour=%Hour%/1
MidStr>%Time%,4,2,Min
MidStr>%Time%,10,1,AMPM

If>AMPM=A,AnteMeridiem

Label>PostMeridiem
Let>AMPM=pm
Goto>Chronos

Label>AnteMeridiem
Let>AMPM=am

Label>Chronos
MessageModal>%Hour%:%Min% %AMPM%
Thank you for the help! I really appreciate it! :)

bigred
Newbie
Posts: 10
Joined: Fri Jul 16, 2004 7:50 am

Post by bigred » Sun Jul 25, 2004 9:49 am

:( Looks like I spoke too soon. Using GetTime along with the rest of the code works fine so long as its 10, 11 or 12 o'clock... If its 1-9, there is no preceding "0" so the string selections get all messed up.

I'm really bad at this stuff. If only I had payed attention in Computer Science class in High School, rahter than talking to the girl beside me... :oops:

EDIT: I think I've solved it. How does the code look?
GetTime>Time
Length>%Time%,Len
If>Len=10,1digit

MidStr>%Time%,1,2,Hour
MidStr>%Time%,4,2,Min
MidStr>%Time%,10,1,AMPM
Goto>CaseConvert

Label>1digit
MidStr>%Time%,1,1,Hour
MidStr>%Time%,3,2,Min
MidStr>%Time%,9,1,AMPM

Label>CaseConvert
If>AMPM=A,AnteMeridiem

Label>PostMeridiem
Let>AMPM=pm
Goto>Chronos

Label>AnteMeridiem
Let>AMPM=am

Label>Chronos
MessageModal>%Hour%:%Min% %AMPM%

Guest

Post by Guest » Sun Jul 25, 2004 4:11 pm

The code looks fine.
rahter than talking to the girl beside me
which is definitely okay :D

You can still play with bits and bytes when you get bald, eat while your teeth having a bath in a glass of water and those tasty girls seems not to be interested anymore in you (depends on the level of cash you own) :lol:

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts