MacroUser1 Posted December 27, 2023 Report Share Posted December 27, 2023 Hello, I have two dates in am looking to change in a URL. Id like the macro to change the dates dynamically so that when it loads website it adjusts the first date to two days ago and adjusts the second date to 4 days ago in the mm/dd/yyyy format. Is this possible in macro express? Would this use a variable? An example of the URL www.example.com/12341/2fjj/StartDate=12/25/2023&EndDate=12/23/2023/(Remainder of URL) Quote Link to comment Share on other sites More sharing options...
Cory Posted December 27, 2023 Report Share Posted December 27, 2023 Yes. Yes. Quote Link to comment Share on other sites More sharing options...
acantor Posted December 27, 2023 Report Share Posted December 27, 2023 It's doable. But to make it bulletproof, it might be complex, at least a little. I'm trying a non-bulletproof proof-of-concept, so stay tuned. Quote Link to comment Share on other sites More sharing options...
Cory Posted December 27, 2023 Report Share Posted December 27, 2023 I think it could be bulletproof. Just build the string. I'd show but the OP doesn't make any indication as to where the variable date values would come from. Offset from today? User input? A file? And the only string variables needed would be for the dates. The rest could exist in the command. Quote Link to comment Share on other sites More sharing options...
acantor Posted December 27, 2023 Report Share Posted December 27, 2023 This code might get you started. The task would be much easier if the Start Day and End Day were based on today's date! I haven't messed with the code enough to massage the variables into a form that will allow dates to be subtracted and added. All this code does is extract the Start Date from the URL and place the day, month, and year into variables. // Get URL Variable Set String %Url% to "www.example.com/12341/2fjj/StartDate=12/25/2023&EndDate=12/23/2023/Blablabla" // Extract %StartDate% from the URL Variable Set Integer %StartDatePos% to the position of "StartDate=" in %Url% Variable Modify Integer: %StartDatePos% = %StartDatePos% + 10 Variable Modify String: Copy part of text in %Url% starting at %StartDatePos% and 10 characters long to %StartDate% // From %StartDate%... extract Day, Month, and Year Variable Modify String: Copy part of text in %StartDate% starting at 1 and 2 characters long to %StartDateMonth% Variable Modify String: Copy part of text in %StartDate% starting at 4 and 2 characters long to %StartDateDay% Variable Modify String: Copy part of text in %StartDate% starting at 7 and 4 characters long to %StartDateYear% // Display results so far Text Box Display: Display components of "%StartDate%" <COMMENT Value="Get URL" _BACK="0080FFFF"/> <VARIABLE SET STRING Option="\x00" Destination="%Url%" Value="www.example.com/12341/2fjj/StartDate=12/25/2023&EndDate=12/23/2023/Blablabla" NoEmbeddedVars="FALSE"/> <COMMENT/> <COMMENT Value="Extract %StartDate% from the URL" _BACK="0080FFFF"/> <VARIABLE SET INTEGER Option="\x0E" Destination="%StartDatePos%" Text_Variable="%Url%" Text="StartDate=" Ignore_Case="TRUE"/> <VARIABLE MODIFY INTEGER Option="\x00" Destination="%StartDatePos%" Value1="%StartDatePos%" Value2="10"/> <VARIABLE MODIFY STRING Option="\x09" Destination="%StartDate%" Variable="%Url%" Start="%StartDatePos%" Count="10" NoEmbeddedVars="FALSE"/> <COMMENT/> <COMMENT Value="From %StartDate%... extract Day, Month, and Year" _BACK="0080FFFF"/> <VARIABLE MODIFY STRING Option="\x09" Destination="%StartDateMonth%" Variable="%StartDate%" Start="1" Count="2" NoEmbeddedVars="FALSE"/> <VARIABLE MODIFY STRING Option="\x09" Destination="%StartDateDay%" Variable="%StartDate%" Start="4" Count="2" NoEmbeddedVars="FALSE"/> <VARIABLE MODIFY STRING Option="\x09" Destination="%StartDateYear%" Variable="%StartDate%" Start="7" Count="4" NoEmbeddedVars="FALSE"/> <COMMENT/> <COMMENT Value="Display results so far" _BACK="0080FFFF"/> <TEXT BOX DISPLAY Title="Display components of \"%StartDate%\"" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Courier;}}\r\n\\viewkind4\\uc1\\pard\\b\\f0\\fs40 Month = [%StartDateMonth%]\r\n\\par Day = [%StartDateDay%]\r\n\\par Year = [%StartDateYear%]\r\n\\par }\r\n" Left="821" Top="417" Width="638" Height="267" Monitor="0" OnTop="TRUE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _BACK="00FFFFFF"/> Quote Link to comment Share on other sites More sharing options...
acantor Posted December 27, 2023 Report Share Posted December 27, 2023 Unless Macro Express has built-in functions that I'm not finding, it's going to be challenging to subtract from an arbitrary date. It could be a fun project, though. The logic might look something like this: To subtract 2 days from the current date: If Day > 3 Then Day = Day - 2 (No need to modify Month or Year) If Day = 2 Then... Case Month = January Month = December Day = 31 (No need to modify Year) Case Month = February Month = December Day = 31 (No need to modify Year) Case Month = March Month = February Day = 28 .... (unless it's a leap year... ) (No need to modify Year) etc. I'm not sure how to proceed without writing a lot of code! Hopefully there's a less onerous solution. Quote Link to comment Share on other sites More sharing options...
rberq Posted December 27, 2023 Report Share Posted December 27, 2023 41 minutes ago, acantor said: Unless Macro Express has built-in functions that I'm not finding, it's going to be challenging to subtract from an arbitrary date. It could be a fun project, though. The logic might look something like this: acantor, I have some code that looks like yours, and it gets complex if you want it to work one-hundred percent correctly over month ends and year ends and leap years, never mind the occasional leap century. Here's a way I just tested manually. It worked well, though visually you might not like it flashing on your screen while the macro runs: 1- Open Excel (new, empty spreadsheet) 2- Paste your known date into cell A1 3- Arrow down to cell A2 4- Type "=A1-2" and ENTER -- decrements the date by two days 5- Arrow back up to cell A2 6- Ctlr-c to copy the two-days-previous date into the clipboard 7- Open Notepad and paste (or, in a macro, set a text string from the clipboard) 8- Close Excel At least with my Excel 2010, Excel treats the mm/dd/yyyy as a date for calculation but as text when I copy to clipboard. I haven't tried putting the above logic into a macro, but as I say, it works when I do it manually. Quote Link to comment Share on other sites More sharing options...
rberq Posted December 28, 2023 Report Share Posted December 28, 2023 Above, in a macro -- works for me. Program Launch: "Excel" (Normal) Parameters: Delay: 500 milliseconds Text Type (Simulate Keystrokes): 12/15/2023<ENTER> Text Type (Simulate Keystrokes): =a1-2<ENTER> Text Type (Simulate Keystrokes): <ARROW UP> Delay: 250 milliseconds Text Type (Simulate Keystrokes): <CTRLD>c<CTRLU> Delay: 250 milliseconds Variable Set String %dat% from the clipboard contents Text Box Display: Date-%dat% Quote Link to comment Share on other sites More sharing options...
Cory Posted December 28, 2023 Report Share Posted December 28, 2023 Of course you can add and subtract days. This complexity and using other apps is not necessary. Date/Time is at its core a decimal is one needs a more sophisticated operation. But just look at the Variable Modify Date/Time. You can add or subtract an integer value and select that to represent a second, day, month, year... Quote Link to comment Share on other sites More sharing options...
acantor Posted December 28, 2023 Report Share Posted December 28, 2023 Cory: I got stumped when I tried to express a date in decimal. Is there a way to do the transformation from within Macro Express? rberq: I didn't realize one could do that in Excel! It might be flashy, but it might be the ticket in the event there isn't a method built into Macro Express. Perhaps there's a web-based app to do the magic rather than using Excel. Since the problem is about renaming URLs, maybe a browser is already open. Quote Link to comment Share on other sites More sharing options...
Cory Posted December 28, 2023 Report Share Posted December 28, 2023 4 minutes ago, acantor said: Is there a way to do the transformation from within Macro Express I just showed you. You don't need ot express it as decimal. If you want the date 5 days ago, subtract 5 days. Maybe you can't see the screenshot I included? Quote Link to comment Share on other sites More sharing options...
Cory Posted December 28, 2023 Report Share Posted December 28, 2023 I must be missing something. WHen did the OP say that where the dates were coming from? Until they respond, I don't see the point of spending time on it. Let's see what they indicate the source it. Then it should be a couple of date commands and whatever command to do something with theURI. That's the other thing. What do they want to do with the URI? If they're using HTTP GET command then one might not even need a string variable for the URI. Quote Link to comment Share on other sites More sharing options...
acantor Posted December 28, 2023 Report Share Posted December 28, 2023 If a web browser is open, insert something like this on the Address line: https://www.timeanddate.com/date/dateadded.html?m1=1&d1=26&y1=2024&type=add&ay=00&am=&aw=&ad=10&rec= This will find a day ten days in the future from January 26. 2024. m1=1 is the month: January is 1, December is 12. d1=26 is the day of the month. y1=2024 is the year. To extract the calculated date from the web page, you'd need to do something like this: Control A // Select the page Copy C // Copy Set %Clip% from Clipboard Set AnswerPosition to "Result:" Copy the next ?? characters to a variable Extract/calculate the values of the day, month, and year into variables. Replace the values in the variable that contains the URL. Still a lot of work!! Quote Link to comment Share on other sites More sharing options...
Cory Posted December 28, 2023 Report Share Posted December 28, 2023 But why don't you just use the Variable Modify Date/Time command and add 10 days? Quote Link to comment Share on other sites More sharing options...
Cory Posted December 28, 2023 Report Share Posted December 28, 2023 This macro sets the variable to today, displays the value, adds 10 days, and displays that. Add 10 days.mex Quote Link to comment Share on other sites More sharing options...
MacroUser1 Posted December 28, 2023 Author Report Share Posted December 28, 2023 Thank you all for the replies! The date, I am looking to have go X amount of days backwards is going backwards from whatever the day is that the link is clicked on. So to answer Cory’s question, it would be offset from today. Reberq, I was using a dynamically updating link in googlesheets, but I want to reduce the amount of steps as possible as I was relying on mouse clicks to pull this off. This was just linking to a cell that was concating the date into the URL. So I am looking to use some sort of variable. Ancator, thank you for the code! I will take a look at that further when I am back in the office. Quote Link to comment Share on other sites More sharing options...
Cory Posted December 28, 2023 Report Share Posted December 28, 2023 Then the macro I provided does the date values in 2 commands. All that's needed is to combine the text to make the URI. Probably 3 more commands. Simple. Quote Link to comment Share on other sites More sharing options...
MacroUser1 Posted December 28, 2023 Author Report Share Posted December 28, 2023 I was able to check. The issue I run into is that the Day/time function you have to change the date does not work with Macro Express 5 and It is a feature in the pro version that I do not have 😔 Quote Link to comment Share on other sites More sharing options...
acantor Posted December 28, 2023 Report Share Posted December 28, 2023 Hope you're consider getting the Pro version! Version 5 and 6 are mostly the same, except during those moments when one needs the extra features. Quote Link to comment Share on other sites More sharing options...
Cory Posted December 28, 2023 Report Share Posted December 28, 2023 You're posting in the wrong forum. YOu can do this still. DT is a decimal. You can subtract the integer 10 from it. Quote Link to comment Share on other sites More sharing options...
Cory Posted December 28, 2023 Report Share Posted December 28, 2023 MEP is worth the investment. Just upgrade. 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.