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 !
It's simple to do like this:-
$date1_good = date('Y/m/d',strtotime($_GET["date1"]));
$date2_good = date('Y/m/d',strtotime($_GET["date2"]));
Note:- I gave an example just change format according to your wish. Good-luck. Thanks. check this:-
<?php
$_GET["date1"] = '22-05-2015';
$_GET["date2"]= '29-05-2015';
$date1_good = date('Y/m/d',strtotime($_GET["date1"]));
$date2_good = date('Y/m/d',strtotime($_GET["date2"]));
echo $date1_good.'----------------'.$date2_good;
?>
Output:- http://prntscr.com/7aofp6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With