Corrupted dBase Bug (DBF) When Using DATE-Field Type

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, October 21, 2008

Follow me on Twitter as @mattiasgeniar

There currently seems to be a bug when using PHP to make a dBase (.DBF) export file and using the DATE-type. Some fields, following the DATE-field, will be shifted a couple of positions to the right, and sometimes even emerge in the next record of the database.

This is the result you get when the following script is run (taken directly from the PHP.NET examples).

It will produce a database, which looks like this when opened in CDBF or DBF Manager.

DBF Manager Layout

DBF Manager Layout

CDBF Layout

CDBF Layout

Notice how in both examples the DATE-field isn’t properly displayed, because the database seems to be corrupted. Both programs show this (al though both show it differently), and any attempt to process the DBF file further will result in unexpected results.

**The solution?

** Create your DBF dBase file without the DATE-type, and replace it by a normal CHAR-type. After your export of the data was done, open the database with a tool such as DBF Manager, and convert the CHAR-type to a DATE-type manually (I agree, this sucks when you’re trying to automate certain tasks, because it requires manual input).

This is what the database looks like when replacing DATE with CHAR.

DBF Manager

DBF Manager

The example above was accomplished with the following code (where the “date”-column is now a “C”-type).

You can change the CHAR-field to DATE by going to the Structure Manager in DBF Manager (CTRL + S as a shortcut), and by changing the type.

DBF Manager - Structure Manager

DBF Manager - Structure Manager

After saving the database, it’ll be stored the way you would have expected it in the first place – with a correct DATE-type.

I’ve filed this as a bug report (#46282), and there seems to be a similar bug reported back in August 2007 (#42261) which also confirms unexpected results when using the DATA-type in a dBase environment, through PHP.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.