Foros del Web » Programando para Internet » PHP »

busqueda entre 2 datatime

Estas en el tema de busqueda entre 2 datatime en el foro de PHP en Foros del Web. buen dia compañeros tengo una duda, se puede hacer una consulta entre 2 datatime en un mismo dia solo cambiando la hora? tengo un sitio ...
  #1 (permalink)  
Antiguo 28/10/2015, 11:15
 
Fecha de Ingreso: octubre-2015
Ubicación: Monterrey
Mensajes: 3
Antigüedad: 8 años, 6 meses
Puntos: 0
busqueda entre 2 datatime

buen dia compañeros
tengo una duda, se puede hacer una consulta entre 2 datatime en un mismo dia solo cambiando la hora?
tengo un sitio con 2 campos input type text y otros dos input type time, los campos tyoe text agregue el calendario con datepicker

Código HTML:
<!DOCTYPE html>
<html>
<head>
	
	<title>Consulta</title>
	<link rel="stylesheet" type="text/css" href="css/default.css" />
	<link rel="stylesheet" type="text/css" href="css/jquery-ui-1.7.2.custom.css" />
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
 	<script type="text/javascript">

jQuery(function($){
	$.datepicker.regional['es'] = {
		closeText: 'Cerrar',
		prevText: '&#x3c;Ant',
		nextText: 'Sig&#x3e;',
		currentText: 'Hoy',
		monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio',
		'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
		monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun',
		'Jul','Ago','Sep','Oct','Nov','Dic'],
		dayNames: ['Domingo','Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;bado'],
		dayNamesShort: ['Dom','Lun','Mar','Mi&eacute;','Juv','Vie','S&aacute;b'],
		dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','S&aacute;'],
		weekHeader: 'Sm',
		dateFormat: 'yy-mm-dd',
		firstDay: 1,
		isRTL: false,
		showMonthAfterYear: false,
		yearSuffix: ''};
	$.datepicker.setDefaults($.datepicker.regional['es']);
});    

        $(document).ready(function() {
           $("#datepicker").datepicker();
        });
    </script>
<body>
<script>
	$(function() {
		$( "#dtm_inicial").datepicker();
		$( "#dtm_final").datepicker();
	});
</script>
<div id="contenido" class="contenedor">
		<h1>Consulta</h1>
		<form name="cosulta" action="01_1consulta_tar_gl.php" method="post">
            <div>
				<label>Fecha Inicial </label>
				<input type="text" name="fechaIni" id="dtm_inicial" readonly="readonly" size="12" required/>
				<input type="time" name="time_Ini" value="03:00:00"/>
			</div>
			<div>
				<label>Fecha Final</label>
				<input type="text" name="fechaFin" id="dtm_final" readonly="readonly" size="12" required/>
				<input type="time" name="time_Fin" value="02:59:59"/>
			</div> 
en mi codigo PHP tengo lo siguiente

Código PHP:
<?php 
        
require('conexion.php');
            
$fec_ini=$_POST['fechaIni'];
            
$hour_ini=$_POST['time_Ini'];
            
$fecha1=$fec_ini."&nbsp;".$hour_ini;
            
$fec_fin=$_POST['fechaFin'];
            
$hour_fin=$_POST['time_Fin'];
            
$fecha2=$fec_fin."&nbsp;".$hour_fin;
    
            
$query "select cunidad, uniras, imonto, count(imonto) from tbltarjetas where itipo<5 and idemp like '%$empresa%' and (dfecha between '".$fecha1."' and '".$fecha2."') group by cunidad, imonto \n";
            
$result mysql_query($query)or die('Consulta fallida: '.mysql_error());
    
            echo 
"<table><th>Unidad</th><th>Uniras</th><th>IMonto</th><th>Total</th>\n";
            while(
$line mysql_fetch_array($resultMYSQL_ASSOC)){
                echo 
"\t<tr>\n";
                foreach (
$line as $col_value){
                    echo 
"\t\t<td>$col_value</td>\n";
                }
                
//echo "\t<\tr>\n";
            
}
        echo 
"</table>\n";
    
// Liberar resultados
        
mysql_free_result($result);
    
?>
Como podran ver tengo concatenado los campos de fecha y time, si los imprimo si me aparece junto pero al realizar la consulta sobre el mismo dia con diferente fecha no me arroja nada, solo si es de diferente dias.

como puedo hacer la consulta o que modifico para que pueda buscar entre fecha y hora.

gracias!!

gracias

Etiquetas: busqueda, fecha, html, mysql, select
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:12.