Jump to content
Macro Express Forums

Date/Time variable from text


Recommended Posts

I've been floundering around with this for most of the day and it still eludes me. For anyone who can come up with a working macro, or practical advice on how to write it, by way of payment I'll send them a 30 second video of a Google Earth tour over their home town or any location of their choice, as well as my warm thanks!

 

I have a date in text form, as 3 separate integers: nDay, nMonth and nYear. I want to calculate the number of days since a fixed previous date. I thought the easiest way would be to convert both dates to Date/Time variables and use Variable Modify Date/Time to make the subtraction. But ME Pro still has no option for inputting a text string. Has anyone written a reliable and easily adaptable subroutine to achieve this, that they're happy to share please? Otherwise I'll ditch that approach and calculate directly.

 

Such a pity that Date/Time variable has no option for this! All it needs is a 'Variable' option within the 'Use a specific date time' option. Hmm - maybe there's some way to dynamically enter that field as part of the running macro?

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

In the PGM Library, which you can now download for free and which contains source code that is now available to you, is a function

{ Date Time - Span of Days }

which appears to meet your needs.

 

Thanks Paul. Excellent timing - I was just about to start writing something from scratch!

 

Original: Saturday 5 November 2011, 07:33, UK time.

 

Latest edit at 16:52

Had some problems (which you may have seen in my earlier edit) but happily re-installing fixed them. The example macro runs fine thanks. Now I just need to adapt it so that no manual user input is needed for the target date, which should be easy.

 

Further edit, Sunday 6 November 2011, 00:06: I have it working now! However, it seems that I must locate this new macro (an adapted version of { DateTime Example - Span of Days }, within the PGM file macro file. Is that essential? It would more appropriate in a category of my own large 'FULL.MEX' file, with all my other macros, but it doesn't run successfully if I do that. I tried using the Macro Filename (Optional) box (which I normally leave empty), but that didn't help.

 

--

Terry, East Grinstead, UK

Link to comment
Share on other sites

Just catching up here, I have been gone to see a client back east.

 

If you look back in my posts you can see I dealt with this very same problem a long time ago and have a macro that will convert date string to any date variable. But it’s quite complex. Another tack one can take depending on the exact needs and date range one can build the date using the date variable manipulation commands. EG take your year, add that number of years to the date variable then add the number of months, then add the number of days. Now you need to tweak some of the values given the nature of serial dates. For instance one needs to subtract 1900 or 1899 from the year since zero is at the beginning of the 20th century. Read the blurb on my website explaining serial dates. Also I think one has to subtract 1 from the day and maybe even the month value. I don’t use it frequently so I always have to run a quick experiment. At one point there was a bug in MEP regarding leap year days or something but I think that has been fixed. And I think if your date is within a hundred years it was moot.

Link to comment
Share on other sites

Further edit, Sunday 6 November 2011, 00:06: I have it working now! However, it seems that I must locate this new macro (an adapted version of { DateTime Example - Span of Days }, within the PGM file macro file. Is that essential? It would more appropriate in a category of my own large 'FULL.MEX' file, with all my other macros, but it doesn't run successfully if I do that. I tried using the Macro Filename (Optional) box (which I normally leave empty), but that didn't help.

Terry, East Grinstead, UK

I can't see any reason why you can't simply paste the code as desired. Of course, the original macro makes calls to several others, all of which use values in the registry that were originally set up when you installed the product. I don't see that any of these values are needed, but you'll have to work out alternative locations and/or alternative methods in order to circumvent them.

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