Karen
|
Posted: 01/03/2002, 7:21 AM |
|
I would like to pass search parameters which are dates formatted as dd-mm-YY while the date field in MySQL database is YY-mm-dd. How do I convert these dates to the correct format for SQL before passing them as parameters? Someone may have posted this before but I can't seem to find it. Can anyone help. I'm using PHP/MySQL. Thanx for any help.
|
|
|
Nicole
|
Posted: 01/04/2002, 1:45 AM |
|
Karen,
if you're sure that the date was passed in dd-mm-yy format from search from to grid from you can format date to MySQL format (yyyy-mm-dd) before search is executed. Add the code like below to result grid form -> Open event. Don't forget to replace table alias and field names with your own ones:
$pdate_assigned = get_param("date_assigned");
if ($pdate_assigned !="")
{
$day = substr($pdate_assigned, 0, 2);
$month = substr($pdate_assigned, 3, 2);
$y = substr($pdate_assigned, 6);
$mysql_date = $y. "-". $month. "-". $day;
$sWhere = str_replace($pdate_assigned, $mysql_date, $sWhere);
}
|
|
|
Karen
|
Posted: 01/04/2002, 2:01 AM |
|
Thanx, Nicole. I did manage to find a similar post and now you've confirm that I need to modify the sWhere variable in the Open event. What I actually did was to leave it out of the input parameters and then in the Open event, converted the date format and appended it to the sWhere variable. It seems to be working fine. Thanx very much for your advice.
|
|
|
|