Jump to content
UBot Underground

Calculate date 30 days prior


Recommended Posts

I need to be able to calculate what the date was 30 days before the current date.

 

Example, if today is 9/9/2014, what was the date 30 days ago?

 

I also will need to be able to do this for 7 days ago.

Link to post
Share on other sites

The450Man,

 

Check out this free plugin:

 

[FREE PLUGIN] DATETIME Manipulation

http://www.ubotstudio.com/forum/index.php?/topic/13665-free-plugin-datetime-manipulation/

 

Now that I look closer, this will give the difference between two dates but may not calculate the date 30 days before.

 

Arunner26

Link to post
Share on other sites

this is what you are looking for

 

http://www.ubotstudi...anced-datetime/

 

set(#aaa$plugin function("Advanced DateTime.dll""$date time current""Short date"), "Global")
set(#aaa1$plugin function("Advanced DateTime.dll""$decrement date/time", 0, 0, 30, 0, 0, 0, 0, #aaa"Short date""Short date"), "Global")

  • Like 1
Link to post
Share on other sites

Okay you JavaScript pros. Not me by any stretch! ;)

Why does my variable Yesterday not work?
 

set(#Today, $eval("var d = new Date();
var n = d.toString();
n;"), "Global")
set(#Yesterday, $eval("var d = new Date();
var e = new Date().setDate(d.getDate()-1);
var n = e.toString();
n;"), "Global")

OBVIOUSLY I am missing something.  LOL

Link to post
Share on other sites

UBotBuddy,

I'm glad to hear it's not just me. I spent time on this yesterday and couldn't make it work with TJ's code. I just hadn't had enough experience with JAVA and/or JAVA with UBOT to make it work.

After seeing what you did, I didn't figure out why yours wasn't working but I came up with this one I like and that works for YYYY/MM/DD format:

set(#Today$eval("var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
if(dd<10)\{dd=\'0\'+dd\}
if(mm<10)\{mm=\'0\'+mm\}
var today = yyyy +\'/\'+mm+\'/\'+dd;
today;"), "Global")
set(#Yesterday$eval("var yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
var dd = yesterday.getDate();    
var mm = yesterday.getMonth()+1;                    
var yyyy = yesterday.getFullYear();    
if(dd<10)\{dd=\'0\'+dd\}
if(mm<10)\{mm=\'0\'+mm\}
yesterday = yyyy +\'/\'+mm+\'/\'+dd;
yesterday;"), "Global")

Andy (Arunner26)

Link to post
Share on other sites

the last variable your setting must be called on its own in javascript.  This echos the information set to that variable.

 

Lets take for-instance you have

var time = Date();

in order to return the value we must call time

var time = Date();
time

So as you see above should help explain better.

 

Also keep in mind with $eval the javascript engine has to be initiated (has been since version 3 of ubot.  Just navigate to google then execute eval's all day long. 

Link to post
Share on other sites

Geee!!!  I was never notified that anyone responded.

 

Anyway, I did find a solution and I tweaked it even more.  So here is my newest version.

 

I will check out what you guys posted later this evening.

set(#OldDate, $trim($substring($PriorDays(30), 0, 10)), "Global")
define $PriorDays(#Days) {
    set(#var, $eval("var x1 = new Date(),
    x2 = x1.getDate(),
    MyX = new Date(x1.setDate(x2-{#Days}));
    MyX;"), "Local")
    return(#var)
}

Link to post
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...