Written by Kevin Heaton, Insight Software Solutions
This sample macro shows how to change a date string to a DateTime variable using the ‘Run Macro in Variable’ command.
Download the macro file umdatestringtodatetimevar.mex and save it to your hard drive. Open the macro file or import the macro into your existing macro file by clicking File, Import, Import Macros.
When you run the macro ‘Sample: MM-DD-YY to DateTime var’ the result will be displayed in a Text Box. However, this macro will provide the most benefit if you study how it works and modify it for your own use.
This macro first parses the date into individual parts: Month, Day and Year. It then creates a ‘Date/Time’ command string and then uses the ‘Run Macro In Variable’ to perform the conversion of the date string into a DateTime variable.
Every macro command can be viewed two different ways: as it appears in the Script Editor and in ASCII format as it appears in the Direct Editor. In the Direct Editor the ‘Date/Time’ command looks like this:
This macro uses the ‘Variable Set String’ command to put this information into a string that can be used by the ‘Run Macro in Variable’ command. There is one thing to take care of, however.
When variables such as %Month%, %Day% or %Year% are used in the ‘Variable Set String’ command they are converted to the content of the variable. In our example, %Month% is converted to 11, %Day% is converted to 12 and %Year% is converted to 2012. This is what we want for these values. But if we use %dtResult% for the result variable it will be converted to the content of %dtResult% which, in this case, will cause the macro command to fail. To avoid the automatic conversion of a variable use \c25 in place of the % characters. So the result variable becomes \c25dtResult\c25, like this:
Once the command in string format is in a variable the ‘Run Macro in Variable’ command puts the date into the variable %dtResult%.
It may be possible to crash Macro Express Pro if you provide an invalid date string. You should add commands to make sure the input variable contains a valid date.
Macro Express Pro
Cookie | Duration | Description |
---|---|---|
cookielawinfo-checkbox-analytics | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics". |
cookielawinfo-checkbox-functional | 11 months | The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional". |
cookielawinfo-checkbox-necessary | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary". |
cookielawinfo-checkbox-others | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other. |
cookielawinfo-checkbox-performance | 11 months | This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance". |
viewed_cookie_policy | 11 months | The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data. |