FileMaker Addict Has Moved!

FileMaker Addict can now be found here: http://www.filemakeraddict.com




Thursday, July 30, 2009

Formatting FileMaker TimeStamp Values with PHP

Have you ever needed to display a FileMaker TimeStamp field value in a PHP solution? If so, you might have run into problems with making the value format nicely.

For example, suppose that you have a timestamp field named "DateTime_Created" with a value of "7/30/2009 9:18:29 PM." If you simply echo the value using PHP code such as...

echo $response->getField("DateTime_Created");

... then the output returned by PHP will look something like this:

07/30/2009 21:18:29


That's not terrible looking, but it's not pretty either.

Suppose that you want to format the value using the type of date/time formatting options that FileMaker provides. The solution is to use a combination of PHP's date and strtotime functions. These functions make it very easy to format timestamp values in a wide variety of ways.

For example, if you want to display the value in a format such as "day name, month day, year" you could use this:

echo date("l, F j, Y", strtotime ($response->getField("DateTime_Created")));


Using that date format, PHP will return:

Thursday, July 30, 2009


The "l, F t, Y" argument that we're passing to the date function is used to specify the format. In this case, the "l" represents the name of the day of the week (Thursday), the "F" represents the name of the month (July), the "j" represents the day of the month (31), and the "Y" represents the year (2009).

Adding the time to the value is easy. You can use this:

echo date("l, F j, Y @ g:i A", strtotime ($response->getField("DateTime_Created")));

... and the output returned by PHP will now look like this:

Thursday, July 30, 2009 @ 9:18 PM


With that format, the "g" represents the hour (9), the "i" represents the minutes (18) and the "A" represents the Ante meridiem or Post meridiem (PM).

To get a better feel for the various formatting options that are available, check out the PHP Date function documentation.

And finally, you might be wondering why the "strtotime" function is necessary. That function converts the FileMaker value into a Unix timestamp. (The "date" function needs the date value to be a Unix timestamp.)

In summary, with PHP's date and strtotime functions, we can easily format FileMaker timestamp values in a wide variety of ways.

Setting FileMaker TimeStamp Fields from PHP

Want to update a FileMaker Timestamp field with the the current date/time via a PHP solution?

Use the PHP date function and format it using something like this: date("m/d/Y h:i:s A")

For example, suppose that you want to update a "Last_Login" field when a user logs in. Your code might look something like this:

$user_update_request = $fm->newEditCommand('PHP_Users', $user->getRecordID());
$user_update_request->setField('Last_Login', date("m/d/Y h:i:s A"));
$user_update_result = $user_update_request->execute();

Wednesday, July 08, 2009

New PHP Error: "PHP has encountered an Access Violation..."

Early this morning, for the first time I had one of our servers that we use to serve up FileMaker/PHP-based solutions throw a PHP error that read "PHP has encountered an Access Violation at 01E02B1B."

From what I've been able to tell, this has something to do with running PHP on a Windows 2003-based server in ISAPI mode. I've cycled IIS and this seems to have solved the problem...

and now I'm waiting to see if this happens again.