Comparing the date part of a date and time field

Use the static DateFromTimestamp method of the DBFunction class to extract the date portion of a java.util.Date field to use in a comparison predicate. The DateFromTimestamp method takes a single parameter, a column reference to a java.util.Date field. The return value is a java.util.Date with only the date portion specified.

DateFromTimestamp(timestamp : ColumnRef) : DBFunction

The following Gosu code uses the DateFromTimestamp method to extract the date from the creation timestamp on activities. The query builder code uses the returned date in a comparison predicate to select activities that were created some time during the current day.

uses gw.api.database.Query
uses gw.api.database.DBFunction
uses gw.api.database.QuerySelectColumns
uses gw.api.path.Paths
uses gw.api.util.DateUtil

// Make a query of Address instances.
var query = Query.make(Address) 

// Query for addresses created today.
query.compare(DBFunction.DateFromTimestamp(query.getColumnRef("CreateTime")), 
              Equals, DateUtil.currentDate())

// Order the result by creation date and iterate the items fetched.
for (address in query.select().orderBy(QuerySelectColumns.path(Paths.make(Address#CreateTime)))) {
  print(address.DisplayName + ": " + address.CreateTime)
}