Jump to content
Macro Express Forums

Adding Time to hh:mm string ?


Recommended Posts

Sometimes in my task managing software i need to defer tasks for 15, 30 or 60 minutes. Unfortunately the software does not provide such a function. So i want to take the start time of a task and change it to a new (later time).
It´s no problem to copy the actual start time in the format "hh:mm"

But i don´t know how to convert the hh:mm string in a date/time variable so i can add minutes .

Does anybody know how to do this?

Thank You very much
Alex

Link to post
Share on other sites

I would parse it into the two parts with the colon. Then use the Variable Modify Date/Time to add the number of hours then add the number of minutes in two steps using the "Integer or value" method.

Link to post
Share on other sites

Thanks Cory,

 

Ok, say we have the time 12:15 and i would like to defer it to 12:45. I copy the string and seperate it in two string variables 12 and 15. How should i put this in the "Variable Modify Date/Time" command. I need to convert those two string variables into a date/time variable, right? How?

 

Thank You

Alex

Link to post
Share on other sites

Could you use the DateTime variables?

 

If you want the time 30 minutes in the future from the current time you can do this:

Date/Time: Set %AdjustedTime% to an adjusted date/time // Set time 30 minutes from now
<DATE/TIME Flags="\xB2" Date="7/3/2014 8:21:49 AM" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="30" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%AdjustedTime%" IsDateVar="TRUE" _COMMENT="Set time 30 minutes from now"/>

If you have the date/time in a variable and it is not the current date/time you could try this:

Date/Time: Set %StartTime% to the current date/time
Date/Time: Set %AdjustedTime% to an adjusted date/time // Set time 30 minutes from now
Variable Modify Date/Time: %DiffTime% = %AdjustedTime% - %StartTime%  // Difference between and 30 minutes from now
<DATE/TIME Flags="\xB0" Date="7/3/2014 8:21:49 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="%StartTime%" IsDateVar="TRUE"/>
<DATE/TIME Flags="\xB2" Date="7/3/2014 8:21:49 AM" Day_Offset="0" Month_Offset="0" Year_Offset="0" Hour_Offset="0" Minute_Offset="30" Second_Offset="0" Left="Center" Top="Center" Monitor="0" Variable="%AdjustedTime%" IsDateVar="TRUE" _COMMENT="Set time 30 minutes from now"/>
<VARIABLE MODIFY DATE/TIME DateVar="%DiffTime%" Option="\x01" LeftVar="%AdjustedTime%" RightVal="%StartTime%" UseInteger="TRUE" MathOpt="\x00" _COMMENT="Difference between and 30 minutes from now"/>

Then add %DiffTime% to the date/time you want to increment.

Link to post
Share on other sites
Date/Time: Set %TimeSample% to the current date/time
Variable Modify Date/Time: %TimeSample% = %TimeSample% + 30 Minutes

I must not be understanding the question. Samrae wouldn't what I have above do the same thing?

Link to post
Share on other sites

// This macro assumes the original start time is in the text variable tTimeStart = say 12:45. It then adds 30 minutes to get the result in the text variable tTimeNew = '13:15'.
Variable Set String %tTimeStart% to "12:45"
// Split as Cory suggested.
Split String "%tTimeStart%" on ":" into %tHrsMins%, starting at 1
Variable Modify String %tHrsMins[1]%: Convert to Integer (%nHrs%)
Variable Modify String %tHrsMins[2]%: Convert to Integer (%nMins%)
// Now define a Date/Time 'zero base', on which to build your adjustments.
// NOTE: There appears to be a bug which crashes MX Pro if this base is set to 00:00:00 as I originally intended. (I've reported it.) That's why I've added one second to my 'base' time.
Date/Time: Set %dtTime% to "27/02/2015 00:00:01"
Variable Modify Date/Time: %dtTimeNew% = %dtTime% + %nHrs% Hours
Variable Modify Date/Time: %dtTimeNew% = %dtTimeNew% + %nMins% Minutes
Variable Modify Date/Time: %dtTimeNew% = %dtTimeNew% + 30 Minutes
Variable Modify Date/Time: Convert to Text String
Text Box Display:

<COMMENT Value="This macro assumes the original start time is in the text variable tTimeStart = say 12:45. It then adds 30 minutes to get the result in the text variable tTimeNew =  '13:15'."/>
<VARIABLE SET STRING Option="\x00" Destination="%tTimeStart%" Value="12:45" NoEmbeddedVars="FALSE"/>
<COMMENT Value="Split as Cory suggested."/>
<SPLIT STRING Source="%tTimeStart%" SplitChar=":" Dest="%tHrsMins%" Index="1"/>
<VARIABLE MODIFY STRING Option="\x04" Destination="%tHrsMins[1]%" Variable="%nHrs%"/>
<VARIABLE MODIFY STRING Option="\x04" Destination="%tHrsMins[2]%" Variable="%nMins%"/>
<COMMENT Value="Now define a Date/Time 'zero base', on which to build your adjustments."/>
<COMMENT Value="NOTE: There appears to be a bug which crashes MX Pro if this base is set to 00:00:00 as I originally intended. (I've reported it.) That's why I've added one second to my 'base' time."/>
<DATE/TIME Flags="\xB1" Date="27/02/2015 00:00:01" 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="%dtTime%" IsDateVar="TRUE"/>
<VARIABLE MODIFY DATE/TIME DateVar="%dtTimeNew%" Option="\x00" LeftVar="%dtTime%" RightVal="%nHrs%" UseInteger="FALSE" MathOpt="\x03"/>
<VARIABLE MODIFY DATE/TIME DateVar="%dtTimeNew%" Option="\x00" LeftVar="%dtTimeNew%" RightVal="%nMins%" UseInteger="FALSE" MathOpt="\x04"/>
<VARIABLE MODIFY DATE/TIME DateVar="%dtTimeNew%" Option="\x00" LeftVar="%dtTimeNew%" RightVal="30" UseInteger="FALSE" MathOpt="\x04"/>
<VARIABLE MODIFY DATE/TIME DateVar="%dtTimeNew%" Option="\x09" LeftVar="HH:mm" RightVal="%tTimeNew%" UseInteger="FALSE" MathOpt="\x00"/>
<TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil Tahoma;}{\\f1\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\qc\\b\\f0\\fs20 tTimeStart\\f1  = \\f0 %tTimeStart%\r\n\\par \r\n\\par tTimeNew\\f1  = \\f0 %tTimeNew%\r\n\\par \r\n\\par \r\n\\par }\r\n" Left="Center" Top="486" Width="278" Height="157" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>

Alexis-AddMinutes.mex

Link to post
Share on other sites

Alexis here's a complete macro as a sample of what I was suggesting. I prompt a user for a time like "12:34" and then I split into a two element array. I then convert the two elements into hour and minute integers. Then I modify the DateTime variable by adding the number of hours, the number of minutes, and 30 minutes as a snooze value. Finally I convert that to a string with the format for just hours and minutes and display the result.

Variable Set String %Clip%: Prompt
Split String "%Clip%" on ":" into %HourMinute%, starting at 1
Variable Modify String %HourMinute[1]%: Convert to Integer (%Hour%)
Variable Modify String %HourMinute[2]%: Convert to Integer (%Minute%)
Variable Modify Date/Time: %TimeSample% = %TimeSample% + %Hour% Hours
Variable Modify Date/Time: %TimeSample% = %TimeSample% + %Minute% Minutes
Variable Modify Date/Time: %TimeSample% = %TimeSample% + 30 Minutes
Variable Modify Date/Time: Convert to Text String
Text Box Display: Result
<VARIABLE SET STRING Option="\x01" Destination="%Clip%" Prompt="Give me a time with colon" Mask="FALSE" OnTop="FALSE" Left="Center" Top="Center" Monitor="0"/>
<SPLIT STRING Source="%Clip%" SplitChar=":" Dest="%HourMinute%" Index="1"/>
<VARIABLE MODIFY STRING Option="\x04" Destination="%HourMinute[1]%" Variable="%Hour%"/>
<VARIABLE MODIFY STRING Option="\x04" Destination="%HourMinute[2]%" Variable="%Minute%"/>
<VARIABLE MODIFY DATE/TIME DateVar="%TimeSample%" Option="\x00" LeftVar="%TimeSample%" RightVal="%Hour%" UseInteger="FALSE" MathOpt="\x03"/>
<VARIABLE MODIFY DATE/TIME DateVar="%TimeSample%" Option="\x00" LeftVar="%TimeSample%" RightVal="%Minute%" UseInteger="FALSE" MathOpt="\x04"/>
<VARIABLE MODIFY DATE/TIME DateVar="%TimeSample%" Option="\x00" LeftVar="%TimeSample%" RightVal="30" UseInteger="FALSE" MathOpt="\x04"/>
<VARIABLE MODIFY DATE/TIME DateVar="%TimeSample%" Option="\x09" LeftVar="h:mm" RightVal="%TimeText%" UseInteger="FALSE" MathOpt="\x00"/>
<TEXT BOX DISPLAY Title="Result" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 %TimeText%\r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
Link to post
Share on other sites

I tried terrypins approach but i get the following errormessage in the line <VARIABLE MODIFY DATE/TIME DateVar="%dtTimeNew%" Option="\x00" LeftVar="%dtTimeNew%" RightVal="%nMins%" UseInteger="FALSE" MathOpt="\x04"/>

Undefined variable or the variable is the wrong type "36524,8333449074"

 

Thank You

Alex

Link to post
Share on other sites

I tried terrypins approach but i get the following errormessage in the line <VARIABLE MODIFY DATE/TIME DateVar="%dtTimeNew%" Option="\x00" LeftVar="%dtTimeNew%" RightVal="%nMins%" UseInteger="FALSE" MathOpt="\x04"/>Undefined variable or the variable is the wrong type "36524,8333449074"

 

Thank You

Alex

Did you open each command one by one and create all variables suggested?

 

Did you try both the code and the MEX file?

 

Terry, East Grinstead, UK

Link to post
Share on other sites

Here is what happened. Each time i copied the macro (Corys) the variable %TimeSample% automatically went from Date/Time Type to Decimal Type. I had to correct this manually for each macro!!! :angry: This is a strange behaviour.

 

The macro itself runs perfectly.

Thank you so much everybody :) :) :)

Link to post
Share on other sites

My macro works fine here. You didn't answer my two questions, and I can't offer further advice until I know exactly what steps you've taken to run it.

 

I tried to run Cory's macro and had similar problems to those you describe, as several variables were of the wrong type.

 

Terry, East Grinstead, UK

Link to post
Share on other sites

Dear Terry, i copied the code from this page. From Corys 4:30 PM Post (#8). What amazes me is that when i copy a line in my script editor i have to reassign the variables in this case %TimeSample% again to the Date/Time Type for every macro. Isn´t that strange?

Link to post
Share on other sites

Dear Terry, i copied the code from this page. From Corys 4:30 PM Post (#8). What amazes me is that when i copy a line in my script editor i have to reassign the variables in this case %TimeSample% again to the Date/Time Type for every macro. Isn´t that strange?

 

You'll have to wait for Cory if you want to discuss his macro!

 

--

Terry, East Grinstead, UK

Link to post
Share on other sites

I thought the variable types would be obvious but I suppose I can spell them out for you. %Clip% is text, %HourMinute% is a text array with 2 elements, %Hour% is integer, %Minute% is integer, %TimeSample% is Date/Time.

Link to post
Share on other sites

 

What amazes me is that when i copy a line in my script editor i have to reassign the variables in this case %TimeSample% again to the Date/Time Type for every macro.

When a macro command needs a variable it offers to create one. In some cases there are multiple types of variables that will work in the command. For example, a command may allow an Integer, a Decimal or a Long Integer. The command tries to guess which one you want and put that one at the top of the drop down list of variable types.

 

Commands that deal with the Date and Time can either be Decimal or DateTime variables. On the surface it does seem that the 'Variable Modify Date/Time' command should default to a DateTime variable. We will investigate to see if it will cause a problem to list the DateTime type first.

Link to post
Share on other sites

The variable types are obvious to me Cory. Whats less obvious is when i copy the line:

 

<VARIABLE MODIFY DATE/TIME DateVar="%TimeSample%" Option="\x00" LeftVar="%TimeSample%" RightVal="%Hour%" UseInteger="FALSE" MathOpt="\x03" _IGNORE="0x0003"/>

 

to another macro %TimeSample% is no longer a Date/Time Variable. So are variable definitions macrospecific and do i have to define them again for each macro?

Link to post
Share on other sites
  • 2 weeks later...

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