I'm sending Date through a Get URL. Those dates are coming from my input in dd-mm-yyyy format but sent through the URL under mm-dd-yyyy format to much the bdd format.
Can you help to do the conversion and keep them as strings so I can use them in my query and where exactly I should do it, in my JS code or in the controller code?
Update
$('#CodeFinition').change(function(){
var periode=$("#Période").val();
var DebutFin = periode.split(' - ');
var debut = DebutFin[0];
var fin = DebutFin[1];
debut =debut.replace(new RegExp('/', 'gi'),'-');
fin =fin.replace(new RegExp('/', 'gi'),'-');
var marque = $("#CodeMarque").val();
var modele = $("#CodeModele").val();
var finition = $("#CodeFinition").val();
console.log(debut);
$.ajax({
url:'home/Calculer',
method:"GET",
data: {debut:debut, fin:fin, marque:marque, modele:modele, finition:finition}, //data body
cache : false,
async: true,
debut and fin are under dd-mm-yyyy format but I should send them under mm-dd-yyyy format so i can use them here :
$marque = $request->get('marque');
$modele = $request->get('modele');
$finition = $request->get('finition');
$debut = $request->get('debut');
$fin =$request ->get('fin');
echo $debut;
echo $fin;
$TotalAproduire = 100;
$Commande = DB::connection('sqlsrv2')->table('Commande_nadine')
->join('finition','Commande_nadine.CodeFinition','=','finition.CodeFinition')
->whereDate('Commande_nadine.DATE_DOCUMENT_CMD_ACHAT_FRS',">",''.$debut.'')
->whereDate('Commande_nadine.DATE_DOCUMENT_CMD_ACHAT_FRS',"<",''.$fin.'')
->where('finition.CodeFinition',"=",$finition)
->where('finition.CodeModele','=',$modele)
->where('finition.CodeMarque','=',$marque)
->count('Commande_nadine.RECID_NADIN');
Split the date with -
and now join again according to your desired structure.
Here i swapped element of index 0
and 1
as you just wanted to interchange month and date.
let str = `01-12-1994`
let dateArray = str.split('-')
let desiredDate = dateArray[1]+'-' + dateArray[0] + '-' + dateArray[2]
console.log(desiredDate)