Open Source Content Management System

Midgard PHP - how to handle datetimes

  1. Datetimes in MidCOM
  2. Examples
    1. Wrong code
    2. Correct code

One of many MgdSchema objects' advantages is the possibility to handle dates in the ISO datetime format.

Unfortunately PHP4 doesn't provide datetime or date variable types. Due to this limitations, any property defined with datetime type is represented as custom string on PHP level.

You can of course write fully reflected code with midgard_reflection_property class help but while writing and reading properties which hold ISO formatted datetime, you should be aware that you are responsible for creating well formatted ISO datetime strings.

Datetimes in MidCOM

Since version 2.6.1, MidCOM DBA handles Midgard datetimes by transparently converting them to and from Unix timestamps.

However, with Query Builder the datetimes must be handled as shown in the example below.

Examples

Wrong code

$qb = new midgard_query_builder("midgard_article");
$qb->add_constraint("metadata.created", ">", "20061108");

Correct code

$qb = new midgard_query_builder("midgard_article");
$qb->add_constraint("metadata.created", ">", "2006-11-08 00:00:00");

As of Midgard 1.8, no other database but MySQL is supported. MySQL itself doesn't support timezone information stored in ISO datetime value but instead all datetimes are considered to be in the UTC timezone.

Designed by Nemein, hosted by Anykey