Grails - Convert String data to Date -


lets say, have "book" class field "availableon"(as shown below).

class book {     string availableon; } 

the fields holds values

  • "all days" or
  • string representation of date. example "13/06/2012"

how can books available within next 2 days? below code throw exception ("java.util.date cannot cast java.lang.string")

def books = c.list(){     between('availableon', new date(), new date() + 2) } 

ps : working on legacy db, , not suppose change schema :(

i think there 2 problems between statement have:

  • availableon cannot converted date comparison when value all days
  • even when availableon has date value in it, not converted date comparison

i'd try along lines of this:

def = new date() def books = book.findallbyavailablenotequal("all days").findall { book ->     date.parse('dd/mm/yyyy', book.availableon) > && date.parse('dd/mm/yyyy', book.availableon) < now+2 } 

clearly, can done in nicer way (adding methods domain class example), should illustrate idea...


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -