che_anj
08-31-2007, 11:28 AM
hello anyone could help me how loop this code below..
list($day,$month,$year)=explode('/',$_POST['startdate']);
echo $start=$year.'-'.$month.'-'.$day;
list($day,$month,$year)=explode('/',$_POST['completiondate']);
echo $completion=$year.'-'.$month.'-'.$day;
list($day,$month,$year)=explode('/',$_POST['interviewdate']);
echo $interview=$year.'-'.$month.'-'.$day;
tnx..
Mwnciau
08-31-2007, 11:30 AM
You could use a function:
function convertDate($date){
list($day,$month,$year)=explode('/',$date);
return $year.'-'.$month.'-'.$day;
}
echo convertDate($_POST['startdate']);
echo convertDate($_POST['completiondate']);
echo convertDate($_POST['interviewdate']);
che_anj
08-31-2007, 11:45 AM
I noticed a space with the result in the second value of $_POST[completiondate]..
2007-08-01
2007 -08-02 //space in year 2007 -08
2007-08-03
tnx.
Bahamut
08-31-2007, 11:51 AM
$_POST['firstname'] = 'firstname';
$_POST['lastname'] = 'lastname';
$_POST['startdate'] = '19/10/1976';
$_POST['completiondate'] = '26/12/1950';
$_POST['interviewdate'] = '17/12/2005';
foreach ($_POST as $key => $val)
{
$tmp = explode('/',$_POST[$key]);
if (count($tmp) == 3)
{
$_POST[$key] = $tmp[2] .'-'. $tmp[1] .'-'. $tmp[0];
}
}
foreach ($_POST as $key => $val)
{
echo "<p>$key = $val";
}
Mwnciau
08-31-2007, 11:55 AM
function convertDate($date){
list($day,$month,$year)=explode('/',$date);
return trim($year).'-'.trim($month).'-'.trim($day);
}
echo convertDate($_POST['startdate']);
echo convertDate($_POST['completiondate']);
echo convertDate($_POST['interviewdate']);
That should get rid of any spaces
I noticed a space with the result in the second value of $_POST[completiondate]..
2007-08-01
2007 -08-02 //space in year 2007 -08
2007-08-03
tnx.
che_anj
08-31-2007, 12:16 PM
tnx guys.. you have different ideas but it all works... :)