Dominique De Cooman
Published on Dominique De Cooman (https://dominiquedecooman.com)

Home > Drupal CCK date field : How to compare a date in the format YY-MM-DDThh:mm:ss allready in database to a unix time stamp

Dominique De Cooman
Wednesday, October 15, 2008 - 13:20

In the query I want get all nodes from the type eclasses between two certain dates. The date stored in the database are in the YY-MM-DDThh:mm:ss format. So how do we compare it to a Unix timestamp or even a date from the same format.
Use the mysql function UNIX_TIMESTAMP()
The query will look like this:

$result = db_query("SELECT nid, field_datum_value FROM {content_type_eclasses} WHERE UNIX_TIMESTAMP(field_datum_value) > %d AND UNIX_TIMESTAMP(field_datum_value2) < %d ORDER BY field_datum_value ASC", $time, $time2);  


Source URL: https://dominiquedecooman.com/blog/drupal-cck-date-field-how-compare-date-format-yy-mm-ddthhmmss-allready-database-unix-time-stamp