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 converteddate
comparison when valueall days
- even when
availableon
has date value in it, not converteddate
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
Post a Comment