将日期与空值进行比较
Compare a date with null value
我正在使用自定义适配器在 activity 中展示一些 post(由用户创建)。在自定义适配器的构造函数中,我使用以下代码来获取查询结果。
ParseQuery query = new ParseQuery("Post");
query.whereWithinMiles("location_point", my_point, 500);
query.whereGreaterThan("expire_date", new Date());
return query;
目标是 - 用户可以为每个post设置一个过期日期,这样post在过期后将不再可见。我正在尝试将 expire_date 列与 当前时间 进行比较,以检查 post 是否已过期。
行query.whereGreaterThan("expire_date", new Date());
是后来添加的。所有先前创建的行在 expire_date 列中都有一个 null 值。
因此,每次我 运行 查询时, 在 expire_date 列 中具有日期对象 的所有行都会被检查 根据条件。在 expire_date 列 中具有空值 的行 永远不会 returned。
注意:expire_date 列不是必填字段(用户可以在创建 post 时选择将其留空)。
是的,我可以为所有 empty/null 字段设置默认日期以与过期日期进行比较。但我很想知道是否有办法让我可以 return 所有具有空值的行或将当前时间与具有 whereGreaterThan
条件的空对象进行比较?
ParseQuery notExpiredPosts = new ParseQuery("Post");
query.whereGreaterThan("expire_date", new Date());
ParseQuery noExpiredDate = new ParseQuery("Post");
query.doesNotExist("expire_date");
ParseQuery expiredDateQuery = ParseQuery.or(notExpiredPosts, noExpiredDate);
ParseQuery query = new ParseQuery("Post");
query.whereWithinMiles("location_point", my_point, 500);
query.whereMatchesKeyInQuery("objectId", "objectId", expiredDateQuery);
return query;
[(NotExpiredPost || NoExpiredDate) & (location_point within 500 mile)]
这就是你想要的,不是吗?
希望对您有所帮助:)
我正在使用自定义适配器在 activity 中展示一些 post(由用户创建)。在自定义适配器的构造函数中,我使用以下代码来获取查询结果。
ParseQuery query = new ParseQuery("Post");
query.whereWithinMiles("location_point", my_point, 500);
query.whereGreaterThan("expire_date", new Date());
return query;
目标是 - 用户可以为每个post设置一个过期日期,这样post在过期后将不再可见。我正在尝试将 expire_date 列与 当前时间 进行比较,以检查 post 是否已过期。
行query.whereGreaterThan("expire_date", new Date());
是后来添加的。所有先前创建的行在 expire_date 列中都有一个 null 值。
因此,每次我 运行 查询时, 在 expire_date 列 中具有日期对象 的所有行都会被检查 根据条件。在 expire_date 列 中具有空值 的行 永远不会 returned。
注意:expire_date 列不是必填字段(用户可以在创建 post 时选择将其留空)。
是的,我可以为所有 empty/null 字段设置默认日期以与过期日期进行比较。但我很想知道是否有办法让我可以 return 所有具有空值的行或将当前时间与具有 whereGreaterThan
条件的空对象进行比较?
ParseQuery notExpiredPosts = new ParseQuery("Post");
query.whereGreaterThan("expire_date", new Date());
ParseQuery noExpiredDate = new ParseQuery("Post");
query.doesNotExist("expire_date");
ParseQuery expiredDateQuery = ParseQuery.or(notExpiredPosts, noExpiredDate);
ParseQuery query = new ParseQuery("Post");
query.whereWithinMiles("location_point", my_point, 500);
query.whereMatchesKeyInQuery("objectId", "objectId", expiredDateQuery);
return query;
[(NotExpiredPost || NoExpiredDate) & (location_point within 500 mile)]
这就是你想要的,不是吗?
希望对您有所帮助:)