Groovy, get list of current week and last 2 weeks -


I got a domain job with ID, day, list day since January. I get the current time from the code:

  def current = new date ()   

Therefore, I want to get list day from last 2 weeks I am included this week, so I have used the following code but it does not work.

  def getWeek = current.Time - 13 (13 2 weeks + today)   

Please help me solve it.

100% sure that I understand, but you should be able to use a range:

  def current = new date (). ClearTime () def listOfDays = (current-13) .. current listOfDays.each {println it}   

It prints:

  Mercury Apr 09 00:00:00 BST 2014 Thu Apr 10 00:00:00 BST 2014 Fri Apr 11 00:00:00 BST 2014 Sat 12 Apr 00:00:00 BST 2014 Sun Apr 13 00:00:00 BST 2014 Mon Apr 14 00:00:00 BST 2014 Tuesday April 15 00:00:00 BST 2014 Wed Apr 16 00:00:00 BST 2014 Thurs Apr 17 00:00:00 BST 2014 Fri Apr 18 00:00:00 BST 2014 Sat Apr 19 00:00:00 BST 2014 Sun Apr 20 00:00:00 BST 2014 Mon Apr 21 00:00:00 BST 2014 Mars A April 22 00:00:00 BST 2014   

If you mean that you want the entire week before the current week and for the current week, you can do it:

  DRF current = new date (). Clear time () Int daydays = calendar.with stains.with {get time = present (calendar.DAY_OF_WEEK)} def listOfDays = (current - 13 - present day) .. (current +7 - present day) Which print:  
  Sun Apr 06 00:00:00 BST 2014 Mon Apr 07 00:00:00 BST 2014 Tuesday April 08 00:00:00 BST 2014 Wed Apr 09 00:00:00 BST 2014 Guru 10th April 00 hrs 2014 BST 2014 Fri Apr 11 00:00:00 BST 2014 Sat 12 Apr 00:00:00 BST 2014 Sarah April 13 00:00:00 BST 2014 Mon Apr 14 00:00:00 BST 2014 Tuesday April 15 00:00:00 BST 2014 Mercury April 16 00:00:00 BST 2014 Thursday 17 April 00:00:00 BST 2014 Fri Apr 18 00:00:00 BST 2014 Sat Apr 19 00:00:00 BST 2014 Sun Apr 20 00:00:00 BST 2014 Mon Apr 21 00:00:00 BST 2014 Tuesday April 22 00:00:00 BST 2014 Wed Apr 23 00:00:00 BST 2014 Master 24 April 00 AM 2014 BST 2014 Fri Apr 25 00:00:00 B ST 2014 Sat Apr 26 00:00:00 BST 2014   

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -