Keeping Dates Current in Demo Data

One of the things I wanted to have for the Tasks Pro™ launch is a demo that is already populated with a real usage scenario. A couple of users, inter-related tasks, stuff like that. I enlisted my Mom’s help in entering the demo data; she works for a consulting company and created a great scenario (complete with dates and all) for a team preparing a presentation.

When we had the data just right, I exported everything to a SQL script and created a CRON job to restore the data every night. Now the only problem was the due dates for all the tasks. Each day, the tasks were getting further and further out of date.

A quick search found this article which explains how to use MySQL’s DATE_ADD() function to extend dates.

I then wrote a little PHP script to get the number of days from the date I want to use as my base and extend the dates accordingly:

$days = ceil((mktime() - mktime(0, 0, 0, 2, 21, 2004))
    / 86400 // divide by 1 day
$result = mysql_query("UPDATE tasks "
    ."SET date_due = "
    ."DATE_ADD(date_due, INTERVAL $days DAY) "
    ."WHERE date_due != '0000-00-00' "

and added it to the CRON job.

Now after the data is restored each night, the dates are all extended appropriately.

Sidenote: The :scare: Mom Test :/scare: is something all software should go through before it is released. Thanks again for all the help Mom! 🙂

This post is part of the project: Tasks Pro™. View the project timeline for more context on this post.