vendredi 29 mai 2015

Concatenate Integers without calculate PHP

On my database, dates are in the format DD-MM-YYYY. But for a SELECT, I need to be between two dates.
I know I must use BETWEEN syntax but with this, I need the date to be in the format YYYY/MM/DD.
So here's my code to change the syntax :

// my URL is : '.../pdf.php?date1=22-05-2015&date2=29-05-2015'
$date1=explode('-',$_GET["date1"]); // $_GET["date1"] = '22-05-2015'
$date2=explode('-',$_GET["date2"]); // $_GET["date2"] = '29-05-2015'

$date1_good = $date1[2].'/'.$date1[1].'/'.$date1[0];
$date2_good = $date2[2].'/'.$date2[1].'/'.$date2[0];

The problem is, $date1_good and $date2_good are now float values and not a string like '2015/05/29'.
I have tried using strval() and (string) but nothing worked.
Do you have any idea to make it work ? Thank you !

Aucun commentaire:

Enregistrer un commentaire