Help with Date

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
mikeeam
Posts: 10
Joined: Thu Jul 07, 2011 4:54 pm

Help with Date

Post by mikeeam » Tue Mar 19, 2013 11:24 am

Hello!

Hope someone help me.

I need the macro to input the last month. So it would get the local date -1. It would be filling two differents websites. One gives me automatically the actual month, so I just extracted the value and add -1. Like this:

Code: Select all

TAG POS=1 TYPE=SELECT FORM=NAME:aspnetForm ATTR=ID:ctl00_body_ddlMes EXTRACT=TXT
SET !VAR1 {{!EXTRACT}}
ADD !VAR1 -1
TAG POS=1 TYPE=SELECT FORM=NAME:aspnetForm ATTR=ID:ctl00_body_ddlMes CONTENT={{!VAR1}}
Works fine. Now in another site, I used this (searched forum and found):

Code: Select all

SET !VAR4 EVAL("var month = new Date(); var lastmonth = new Date(); lastmonth.setDate(month.getMonth()); var mnt = lastmonth.getDate().toString(); if (mnt.length < 2) {mnt = \"0\" + mnt;};var year = lastmonth.getFullYear().toString(); var dateString = mnt + \"/\" + year; dateString;")
Which works too, but I have no idea where he gets the last month variable. Well, the problem is in January. Both need to identify if its January, and if so, it would set the var as 12 instead of 0, and in the first case, change the year too.

I have tried this, but didnt work:

Code: Select all

SET !VAR1 EVAL("var month = new Date(); var lastmonth = new Date(); lastmonth.setDate(month.getMonth()); var mnt = lastmonth.getDate().toString(); if (mnt == 0) {mnt = 12;}; var dateString = mnt; dateString;")
Or even

Code: Select all

SET !VAR1 EVAL("var month = new Date(); var lastmonth = new Date(); lastmonth.setDate(month.getMonth()); var mnt = lastmonth.getDate().toString(); if (mnt.length < 2) {mnt = \"0\" + mnt;};var year = lastmonth.getFullYear().toString(); var dateString = mnt + \"/\" + year; dateString;")
It returns "31" instead of "12".

Thank you!
Post Reply