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

Posted by: 
Dominique De Cooman

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);  

Comments

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

Thank you, this works great. Way better than the views query method.

Add new comment