jrgreenman Posted November 11, 2010 Report Share Posted November 11, 2010 I see commands to store date/time vars in strings, and do all kinds of date math. But I can't seem to find a way to convert a string variable to date/time. Is there a way to do this? Quote Link to comment Share on other sites More sharing options...
paul Posted November 12, 2010 Report Share Posted November 12, 2010 You can concert a string variable to decimal, then the decimal variable to date/time. Does this help? Quote Link to comment Share on other sites More sharing options...
jrgreenman Posted November 12, 2010 Author Report Share Posted November 12, 2010 My string is in the form MM/DD/YYYY. So I was hoping for a native command that would operate on a date in that format or some other elegant way to manage this. Thanks for the tip, though. Converting to decimal and then to date/time could be part of the solution (once I convert MM/DD/YYYY to the relevant decimal equivalent). Quote Link to comment Share on other sites More sharing options...
terrypin Posted November 12, 2010 Report Share Posted November 12, 2010 If Cory is around he's an acknowledged expert on date/time stuff. Here's an old thread in which he makes a macro available that might do what you want. Or give you a start anyway. http://pgmacros.invisionzone.com/index.php?showtopic=3763 I see that in the five or so years that have elapsed there's still no built-in command to convert directly from text to date/time! If you do come up with a generic 'elegant' macro, maybe you could publish it? ------------------------- Edit: One somewhat way out approach I subsequently thought of would be as follows. Install a little program called Attribute Changer (free, many sources). Or any of several similar utilities that allow you to change the date/time info of a file. Then write a simplish macro to: 1. R-click (or Shift+F10) a temporary file; any type, any content (including none), created permanently just for this purpose. 2. Select 'Change Attribute', an addition to the XP shell added by Attribute Changer. 3. Parse your MM/DD/YYYY (easy) to get 3 string variables: tM, tD and tY 4. Enter your text MM/DD/YYYY as the new Modified or Created Date; use those 3 variables as you cannot paste the whole field; then close the dialog. 5. Use the ME Pro command Variable Set File with that temporary file as its target and this little known configuration: 6. Your required result should be in that Date/Time variable. I tested most of it, using the far more logical DD/MM/YYYY , but I think it reflects Control Panel > Regional and Language Options settings. And I'm using XP Pro, but expect it would be very similar in another OS like Win 7. -- Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
jrgreenman Posted November 12, 2010 Author Report Share Posted November 12, 2010 Thanks for all the tips guys. In the end, I piggybacked off the PGM Macros (the PGM library has some great date/time functions already) to come up with the following macro "Convert Date To Decimal" <COMMENT Value="Set String \"DateString\" before calling. Returns \"DateDecimal\""/> <WRITE REGISTRY VALUE Key="HKEY_CURRENT_USER\\Software\\Professional Grade Macros\\Parameters\\ParameterString1" Destination="%DateString%"/> <MACRO RUN Use_ID="FALSE" Name="{ DateTime - Format Input String }" ID="-1" Wait="TRUE"/> <READ REGISTRY VALUE Key="HKEY_CURRENT_USER\\Software\\Professional Grade Macros\\Parameters\\ReturnString1" Destination="%lclDateString%"/> <WRITE REGISTRY VALUE Key="HKEY_CURRENT_USER\\Software\\Professional Grade Macros\\Parameters\\ParameterString1" Destination="%lclDateString%"/> <MACRO RUN Use_ID="FALSE" Name="{ DateTime - Date to Julian }" ID="-1" Wait="TRUE"/> <READ REGISTRY VALUE Key="HKEY_CURRENT_USER\\Software\\Professional Grade Macros\\Parameters\\ReturnDecimal1" Destination="%DateDecimal%"/> The nice thing about the above is that the PGM macro "{ DateTime - Format Input String }" takes a variety of date formats as input strings. So this is pretty flexible. Finally, in my case, I'm seeding DateString from a known-good date (not user-typed input) and so stripped out all the error-checking. Maybe I'll be sorry, but not yet. Usage is as follows: <VARIABLE SET STRING Option="\x00" Destination="%DateString%" Value="12/22/2010" NoEmbeddedVars="FALSE"/> <MACRO RUN Use_ID="FALSE" Name="Convert Date to Decimal" ID="-1" Wait="TRUE"/> <VARIABLE SET DECIMAL Option="\x00" Destination="%Result%" Value="%DateDecimal%"/> I think three lines is as tight as I can make it. The most elegant solution would be if MEP supported passing in/out parameters to macros directly using "Macro Run". Then of course we would not have set input values nor retrieve output values using individual lines of code, but could write something like: Macro Run: Convert Date to Decimal ("12/22/2010", %Result%) Can I get an Amen!?!?! Quote Link to comment Share on other sites More sharing options...
Cory Posted November 15, 2010 Report Share Posted November 15, 2010 I have a large macro that mathematically converts string dates to decimal value. But lately I've been running a simple VBScript to do it. The only downside is that there's a couple second overhead to running external scripts with MEP. So for one off things I use VB because it's simple, for repetitive things I use my conversion macro. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.