Jump to content
Macro Express Forums

Help converting Decimal variables to Date Variables


Recommended Posts

I'm working on a script that calculates future times.

 

When the macro first runs, it notes the current time:

 

Date/Time: Set %CurrentDateTimeDate% to the current date/time

<DATE/TIME Flags="\xB0" Date="31-Mar-2024 3:48:26 p.m." 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="%CurrentDateTimeDate%" IsDateVar="TRUE"/>

 

Each time the macro runs, I want the script to advance the clock 65 minutes from the previous run time.

 

I think the way to do this in Macro Express is to convert a Date variable into a Decimal variable, add a "fudge factor" to the Decimal variable, and then convert the Decimal variable back to a Date variable:

 

Convert Date/Time to Decimal: %CurrentDateTimeDate% => %CurrentDateTimeDec%
Variable Modify Decimal: %CurrentDateTimePlusDec% = %CurrentDateTimeDec% + .044
Convert Decimal to Date/Time: %CurrentDateTimePlusDec% => %CurrentDateTimePlusDate%
Text Box Display: 

<CONVERT DATE/TIME TO DECIMAL Source="%CurrentDateTimeDate%" Dest="%CurrentDateTimeDec%"/>
<VARIABLE MODIFY DECIMAL Option="\x00" Destination="%CurrentDateTimePlusDec%" Value1="%CurrentDateTimeDec%" Value2=".044"/>
<CONVERT DECIMAL TO DATE/TIME Source="%CurrentDateTimePlusDec%" Dest="%CurrentDateTimePlusDate%"/>
<TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 %CurrentDateTimeDate%\r\n\\par %CurrentDateTimePlusDate%\r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>

 

Through trial-and-error experimentation, I've found that adding 0.044 to the Date variable adds about 65 minutes.

 

I could do more trials to get closer to 65 minutes. But I'm hoping someone will know how to calculate the exact decimal amount.

 

This would be easy if I want to add 65 minutes to the current time, rather than to the last run time. This does it nicely... but it's not what I need!

 

Date/Time: Set %NextDateTimeDate% to an adjusted date/time

<DATE/TIME Flags="\xB2" Date="31-Mar-2024 3:50:24 p.m." Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="65" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%NextDateTimeDate%" IsDateVar="TRUE"/>

 

 

Link to comment
Share on other sites

Create a decimal and make ir's value by dividing 65 by 1440.

However I think it better to add 65 minutes with the Date/Time command, Date/Time tab, Adjust the current date/time option, and add 65 minutes.

 

Link to comment
Share on other sites

I wish I could add 65 minutes, but I think I can only add it to the current time, not a time I specify via a variable.

 

Thanks for the answer! I see that 65 is the number of minutes, but where does "1440" come from?

Link to comment
Share on other sites

I would use Variable Modify Date/Time, Options tab, Add option, Integer or Value, enter 65, then select minutes. 

  • Thanks 1
Link to comment
Share on other sites

Thank you, Cory, for that suggestion. I got it to work.

 

My 90-line spaghetti-like script (which converted Date variables to and from Decimal variables and failed in puzzling ways), is now a super-reliable 40-line script which doesn't use Decimal variables.

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...