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();
Thursday, July 30, 2009
Subscribe to:
Post Comments (Atom)


5 comments:
Hi Tim,
Just wondering how you handle regular date fields that user's can edit via the web and if they enter invalid dates/invalid characters? The PHP API appears to stop when you try and set a field with invalid data after the page is submitted and stops executing subsequent set field steps.
Steve
Steve --
I use this custom function to check that the value is a valid FileMaker date...
function is_valid_filemaker_date ($test_date)
{
// First, check the format of the date.
if ( !ereg ("^[0-9]{2}/[0-9]{2}/[0-9]{4}$", $test_date) ) {
return false;
}
// Convert the date into an array.
$date_parts = explode("/", $test_date);
// Assign the individual parts to variables.
$month = $date_parts[0];
$day = $date_parts[1];
$year = $date_parts[2];
// Check to see if this is a real date.
if ( checkdate($month, $day, $year) === false ) {
return false;
}
// Check the year to confirm that it is less than or equal to 4000 (the max year supported by FileMaker).
if ( $year > 4000 ) {
return false;
}
// The date passed all tests.
return true;
}
-- Tim
Thanks Tim that looks interesting. I presume this is happening server side after submission - have you attempted to address this before submission/client side? I'm looking into something like a javascript validator at the moment so it can happen before the user clicks the submit button.
Steve
Steve --
Correct, I use this after the form is submitted, during server-side form validation. Client-side form validation is nice, but you can't rely on it because the user can simply disable Javascript. Ideally you'd do both -- client-side validation to pre-validate the data, and then server-side validation before doing anything with that data...
-- Tim
Tim, this is exactly what I was looking for. I should have hopped on the Google earlier!
And it appears as though this time pulls the server time, which in my case is exactly what I want. Thanks a lot for the tip.
Post a Comment