The450Man 0 Posted September 9, 2014 Report Share Posted September 9, 2014 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. Quote Link to post Share on other sites
arunner26 51 Posted September 9, 2014 Report Share Posted September 9, 2014 The450Man, Check out this free plugin: [FREE PLUGIN] DATETIME Manipulationhttp://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 Quote Link to post Share on other sites
stanf 43 Posted September 10, 2014 Report Share Posted September 10, 2014 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") 1 Quote Link to post Share on other sites
The450Man 0 Posted September 10, 2014 Author Report Share Posted September 10, 2014 What about doing this with javascript? I dont like using plugins. Quote Link to post Share on other sites
LoWrIdErTJ - BotGuru 904 Posted September 10, 2014 Report Share Posted September 10, 2014 var today = new Date()var priorDate = new Date().setDate(today.getDate()-30) 1 Quote Link to post Share on other sites
The450Man 0 Posted September 11, 2014 Author Report Share Posted September 11, 2014 I place that inside a variable with the $eval param but I get nothing as a result when ran. Quote Link to post Share on other sites
UBotDev 276 Posted September 11, 2014 Report Share Posted September 11, 2014 You just need to echo variable at the end to get it returned...so add this: priorDate; Quote Link to post Share on other sites
UBotBuddy 331 Posted September 11, 2014 Report Share Posted September 11, 2014 Nice solution guys! I can actually use this today! Buddy Quote Link to post Share on other sites
LoWrIdErTJ - BotGuru 904 Posted September 11, 2014 Report Share Posted September 11, 2014 $eval("var today = new Date();var priorDate = new Date().setDate(today.getDate()-30);priorDate;") Quote Link to post Share on other sites
UBotBuddy 331 Posted September 11, 2014 Report Share Posted September 11, 2014 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 Quote Link to post Share on other sites
arunner26 51 Posted September 12, 2014 Report Share Posted September 12, 2014 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) Quote Link to post Share on other sites
LoWrIdErTJ - BotGuru 904 Posted September 12, 2014 Report Share Posted September 12, 2014 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(); timeSo 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. Quote Link to post Share on other sites
Pete 121 Posted September 12, 2014 Report Share Posted September 12, 2014 If your using SQLite you could just query it SELECT julianday('now') - julianday('2014-08-12'); Quote Link to post Share on other sites
UBotBuddy 331 Posted September 12, 2014 Report Share Posted September 12, 2014 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) } Quote Link to post Share on other sites
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.