Jump to content
Macro Express Forums

Change Date in URL


Recommended Posts


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)

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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"/>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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%

 

Link to comment
Share on other sites

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

image.jpeg.a0cf10893fbb7146edec525319811362.jpeg

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites


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. 

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