Jump to content
Macro Express Forums

Getting current time, ignoring current date


Recommended Posts

Acutally it seems simple but somehow i can´t figure it out.

I want to have a macro timespecific while the current date doesn´t matter. The date should be ignored. For time calculations i convert the date/time variable into an decimal variable, right?

 

So for the 19. of June Time 10:45 i get 42174,4479166667. The number left from the comma is the date. The number right from comma is 10:45.

 

How can create a date/time variable without the date portion? Or how can i delete that portion in the according decimal variable?

 

Thanks a lot

Alex

  • Like 1
Link to comment
Share on other sites

You shouldn't convert to decimal as MEP has the command Variable Modify Date/Time. In there you can extract the hour and minute if you like. Also you can create a time string that displays only the hour and minute. A complete list of formats is in the help file on the "Date/Time" topic. Look for the yellow box.

Link to comment
Share on other sites

Also bear in mind the date/time variables are essentially decimals. 1 is 1/1/1990 and counts up 1 every day. Pretty much the same as all programs including Excel. And the decimal portion it the part of the day so 0.5 is noon. This can be converted into 12:00 representation. But it's all a matter of time intervals. So I can have a period of time like 8 hours stored in a DT variable. And then I could add that to the current date time and know how long I have to work today. So if you think of them all as just periods of time stored in decimal you can see how easy it is.

 

In many of my macros I needed to check the time of day. I could have extracted hours and minutes but to be frank I often just mentally concert to the decimal value and use it. For instance I know that an hour is 0.041[6]. And for most purposes 0.42 is close enough being it's only 29 seconds difference. I often do this in audits of files to check their age. Like if a fax PDF languishes more than 3 hours in the 'inbox' folder I simply check that it's not more than 0.125 days old.

Link to comment
Share on other sites

Thank you so far. I´m getting closer. <_<

 

But now that i want the macro to do A if it´s earlier than 10:45 and to do B if it´s later than 10:45 what are exactly the "If Variable commands" and Variables i need to use. I need to convert the DT Variable to Decimal before, no? And is the number in this Decimal created by the date not disturbing?

 

I tried extracting hour and minutes but then i have to write different If commands including clunky AND Operations for hours and minutes if i treat them as strings.

Link to comment
Share on other sites

Clunky, but easy to understand. I have set the target time to 10:45 in this example. Macro Express seems to extract the hour based on the 24-hour clock.

Variable Set Integer %TargetHour% to 10
Variable Set Integer %TargetMinute% to 45
Variable Set Integer %Hour%: Set to the Current Hour
Variable Set Integer %Minute%: Set to the Current Minute
If Variable %Hour% Is Greater Than or Equal To "%TargetHour%"
  AND
If Variable %Minute% Is Greater Than or Equal To "%TargetMinute%"
  Text Box Display: %Hour%:%Minute% is after %TargetHour%:%TargetMinute%
Else
  Text Box Display: %Hour%:%Minute% is before %TargetHour%:%TargetMinute%
End If

Link to comment
Share on other sites

Thank you but i don´t see where your macro reads out the current time. This is my approach for checking if current time is between 7:00 to 12:45 and i don´t think it´s clunky. :)

 

<DATE/TIME Flags="\xB0" Date="24.02.15 10:45:00" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Left="Center" Top="Center" Monitor="4" Variable="%Jetzt%" IsDateVar="TRUE"/>
<CONVERT DATE/TIME TO DECIMAL Source="%Jetzt%" Dest="%JD%"/>
<VARIABLE MODIFY DECIMAL Option="\x06" Destination="%JD%" Variable="%JI%"/>
<VARIABLE MODIFY DECIMAL Option="\x01" Destination="%JD%" Value1="%JD%" Value2="%JI%"/>
<IF VARIABLE Variable="%JD%" Condition="\x03" Value="0,29166666" IgnoreCase="FALSE"/>
<AND/>
<IF VARIABLE Variable="%JD%" Condition="\x05" Value="0,4583333333" IgnoreCase="FALSE"/>

Link to comment
Share on other sites

Alan, with your approach of two different variabels you have to use IF / AND combination of commands for every time check. But you don´t neeed to conversion of DT Variable and the Truncation before. Both methods are possible.

 

Thanks for sharing insights!

Link to comment
Share on other sites

Cory, it was all about checking if it´s later than a certain time each day. I came up with the idea to subtract the integer part of the resulting decimal. So the date doesn´t matter. Alan came up with creating directly an hour and an minute integer. Everything is mentioned above.

 

Thank you

Alex

Link to comment
Share on other sites

You shouldn't convert to decimal as MEP has the command Variable Modify Date/Time. In there you can extract the hour and minute if you like. Also you can create a time string that displays only the hour and minute. A complete list of formats is in the help file on the "Date/Time" topic. Look for the yellow box.

What the heck!?! Isn't that what I explained to you in my first post?

Link to comment
Share on other sites

Still i find the way using one variable more elegant than dealing with 2 (hour and minute) where you need IF AND commands.

 

@Cory: I checked my posts before posting. Could it be that posts vanish? It says i made 261 posts. But only the last 4 of 2015 are shown. Why? Could be that some people are reposting stuff because of that.

Link to comment
Share on other sites

Still simple. Take the hour integer and multiply by 100 then add the minute value. Now it's a simply less/greater than comparison.

 

I don't know about your messages, sorry.

 

Or how about just comparing the hour/minute string? Only one command and then the comparison.

Date/Time: Set %Time% to an adjusted date/time using "hhnn" as the format
If Variable %Time% Is Greater Than "1045"
  Text Box Display: %Macro Name%
Else
  Text Box Display: %Macro Name%
End If
<DATE/TIME Format="hhnn" Flags="\xB2" Date="6/25/2015 9:41:29 AM" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="0" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%Time%" IsDateVar="FALSE"/>
<IF VARIABLE Variable="%Time%" Condition="\x03" Value="1045" IgnoreCase="FALSE"/>
<TEXT BOX DISPLAY Title="%Macro Name%" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\b\\f0\\fs16 It's after 10:45\r\n\\par }\r\n" Left="Center" Top="Center" Width="300" Height="150" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<ELSE/>
<TEXT BOX DISPLAY Title="%Macro Name%" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\b\\f0\\fs16 It's before 10:45\r\n\\par }\r\n" Left="Center" Top="Center" Width="300" Height="150" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
<END IF/>
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...