PHP Code:<?php
// Try this out:
echo ( date("H:i:s", strtotime("3:30 pm")) );
// MySQL query will select the time in 24 HOUR format and return it in 12 HOUR
$q = "SELECT TIME_FORMAT(time_column, '%r') as time FROM table WHERE ..." ;
Printable View
PHP Code:<?php
// Try this out:
echo ( date("H:i:s", strtotime("3:30 pm")) );
// MySQL query will select the time in 24 HOUR format and return it in 12 HOUR
$q = "SELECT TIME_FORMAT(time_column, '%r') as time FROM table WHERE ..." ;
Thanks for that, but I'd already made the necessary functions...
But while we're on the topic of validation I've made a function to validate the date as well, it works just as intended but I want to know how to return an error if the date is false.
Like : 31/04/2009 - Passes my preg_match() function as it is valid
But 31/04/2009 is not actually valid, and if you insert it into a database it truncates and ends up with 0000-00-00.
I tried the following to catch the error, but having no luck - any suggestions?
PHP Code:// Insert date into empty row to test it is a valid date, e.g. User could input 31/04/2009 which passes the RegExp but is not a valid date
#MySQL error 1265 is output if data truncated
$query = "INSERT INTO appointments (`date`) VALUES('$date')";
if(mysql_query($query))
{
if(mysql_errno() == 1265)
{
die("Invalid date.");
}
}
Ah I see, checkdate's very helpful - but I think it's better that I've made my own functions, as I'm doing it for my A2 coursework, so will hopefully get more marks :)