Joe,
I did find out that PHP has a newer function called strtotime() that is supposed to convert a string into a UNIX timestamp. I had difficulty getting this to work reliably AND it is only available for PHP versions 3.0.12 - 3.0.16 only, PHP4 >= 4.0b2.
No one ever responded to my question, but I did endup writing two simple functions for converting user input to mySQL dates and times. I share them for any and all. They aren't perfect, but they're fairly useful.
The commenting is kind of incomplete, so let me know if you have any questions.
-Bill
/*****************************************************
strtomySQLdate
takes a string and returns a string formatted in the
standard mySQL date format ('YYYY-MM-DD').
*******************************************************/
function strtomySQLdate($datestring)
{
if (ereg("-",$datestring))
{ $date_delimiter = "-"; }
elseif (ereg("/",$datestring))
{ $date_delimiter = "/"; }
elseif (ereg(".",$datestring))
{ $date_delimiter = "."; }
else
{
return(0);
}
$date_array = explode($date_delimiter, $datestring);
if(count($date_array) <> 3)
{
if((count($date_array) == 2) AND ($date_delimiter == "/"))
{
$date_array[2] = date("Y");
}
else
{
return(0);
}
}
switch($date_delimiter)
{
case "-":
$date_month = intval($date_array[1]);
$date_day = intval($date_array[2]);
$date_year = intval($date_array[0]);
break;
case "/":
$date_month = intval($date_array[0]);
$date_day = intval($date_array[1]);
$date_year = intval($date_array[2]);
break;
case ".":
$date_month = intval($date_array[1]);
$date_day = intval($date_array[0]);
$date_year = intval($date_array[2]);
break;
default:
return(0);
}
// mySQL only supports dates up to 2038-12-31
// so I decided to use 38/39 as the dividing point for 2 digit years
if($date_year<39)
{ $date_year = $date_year + 2000; }
elseif($date_year<100 and $date_year>=38)
{ $date_year = $date_year + 1900; }
if (checkdate($date_month, $date_day, $date_year))
{
$new_timestamp = mktime(6,0,0, $date_month, $date_day, $date_year);
$mysqldatestring = date("Y-m-d", $new_timestamp);
}
else
{ return(0); }
return($mysqldatestring);
}
/*****************************************************
strtomySQLtime
takes a string and returns a string formatted in the
standard mySQL time format ('HH:MM:SS').
*******************************************************/
function strtomySQLtime($timestring)
{
// split off am/pm from end of date
$time_array = explode(" ", $timestring);
$ampm_string = $time_array[1];
// split time into hour, minute, and second integers
$time_array = explode(":", $time_array[0]);
$time_hour = $time_array[0];
$time_minute = $time_array[1];
$time_second = $time_array[2];
if (ereg("noon",$timestring))
{
$time_hour = 12;
$time_minute = 0;
$time_second = 0;
}
elseif (ereg("mid",$timestring))
{
$time_hour = 0;
$time_minute = 0;
$time_second = 0;
}
// fix am/pm
// if time is PM, add 12 to the hours integer
elseif ((strtolower($ampm_string) == "pm") or (strtolower($ampm_string) == "p" ))
{
if (($time_hour < 12) AND ($time_hour > 0))
{
$time_hour = $time_hour + 12;
}
elseif (($time_hour == 12) AND ($time_minute == 0 OR $time_second == 0))
{
// the user has entered in 12:00:00 PM which isn't valid
// I'll assume that they meant 12 Noon and make no conversion
}
}
elseif ($ampm_string == "")
{
$earliest_hour_for_appointment = 7;
// uncomment the following lines to apply some artificial intelligence
//if ($time_hour<$earliest_hour_for_appointment) { $time_hour = $time_hour +
12; }
}
$new_timestamp = mktime($time_hour, $time_minute, $time_second, 1, 1, 2000);
return(date("H:i:s", $new_timestamp));
}