Originariamente inviato da Alhazred
Il tuo problema è solo quello dell'ordinamento?
Il formato aaaa-mm-gg
va in ordine benissimo anche se gestito come stringa.
Interessante !
Questo non lo sapevo quindi prendo nota.
Comunque ho risolto il problema facendo la mia funziona strtodate visto che quella ufficiale strtotime è deludente.
codice:
function mystrtodate($kk1, $separatore){
$swErr=false;
//--- inizio mettere il default ---
$matricelocale = explode("-", "1-1-1");
$n3=count($matricelocale);
for($bb = 0; $bb < $n3; $bb++) {
$matricelocale[$bb]="-".$matricelocale[$bb];
}
//--- fine mettere il default ---
$UnaData=trim($kk1);
$n1=strlen($UnaData);
if ($n1 < 1) {
$swErr=true;
$matricelocale = explode("-", "1-1-1");
$n3=count($matricelocale);
for($bb = 0; $bb < $n3; $bb++) {
$matricelocale[$bb]="-".$matricelocale[$bb];
}
} //swErr = false
if (strlen($separatore) < 1) {
$separatore="-";
}
if ($swErr == false) {
$matricelocale = explode($separatore, $UnaData);
$n3=count($matricelocale);
if ($n3 !== 3) {
$swErr=true;
$matricelocale = explode("-", "1-1-1");
$n3=count($matricelocale); // n3=3
for($bb = 0; $bb < $n3; $bb++) {
$matricelocale[$bb]="-".$matricelocale[$bb];
}
} // n3 diverso da 3
} //swErr = false
if ($swErr == false) {
$kk2=$matricelocale[0];
$n2=strlen($kk2);
if ($n2 !== 4) {
$swErr=true;
$matricelocale[0]="-1";
$matricelocale[1]="-1";
$matricelocale[2]="-1";
} // n2 diverso da 4
} // swErr = false
if ($swErr == false) {
//--- inizio mese ---
$AlfaMese=$matricelocale[1]; // mese
$n2=strlen($AlfaMese);
if ($n2 == 0) {
$swErr=true;
$matricelocale[0]="-1";
$matricelocale[1]="-1";
$matricelocale[2]="-1";
}else{
if ($n2 == 1) {
//va bene
}else{
if ($n2 == 2) {
$primo_car=substr($AlfaMese, 0, 1);
//echo "primo carattere a sinistra del mese = ", $primo_car, "
";
if ($primo_car == "0") {
$matricelocale[1]=substr($AlfaMese, 1, 1); // rimuove lo zero
}
}else{
$swErr=true;
$matricelocale[0]="-1";
$matricelocale[1]="-1";
$matricelocale[2]="-1";
}
}
}
//--- fine mese ---
} // swErr = false
if ($swErr == false) {
//--- inizio giorno ---
$AlfaGiorno=$matricelocale[2]; // giorno
$n2=strlen($AlfaGiorno);
if ($n2 == 0) {
$swErr=true;
$matricelocale[0]="-1";
$matricelocale[1]="-1";
$matricelocale[2]="-1";
}else{
if ($n2 == 1) {
//va bene
}else{
if ($n2 == 2) {
$primo_car=substr($AlfaGiorno, 0, 1);
//echo "primo carattere a sinistra del giorno = ", $primo_car, "
";
if ($primo_car == "0") {
$matricelocale[2]=substr($AlfaGiorno, 1, 1); // rimuove lo zero
}
}else{
$swErr=true;
$matricelocale[0]="-1";
$matricelocale[1]="-1";
$matricelocale[2]="-1";
}
}
}
//--- fine giorno ---
} // swErr = false
return $matricelocale;
} //end function
$MiaDataDiNascita="1991-08-22";
$matrice=mystrtodate($MiaDataDiNascita, "-");