Foros del Web » Programando para Internet » PHP »

Problema con Fecha

Estas en el tema de Problema con Fecha en el foro de PHP en Foros del Web. Pues nada resulta que tengo la fecha en formato yyyy/mm/dd guardada en la base de datos y quiero mostrarla en formato dd-mm-yyyy. Qué tengo que ...
  #1 (permalink)  
Antiguo 07/05/2008, 08:18
 
Fecha de Ingreso: mayo-2008
Mensajes: 10
Antigüedad: 16 años
Puntos: 0
Problema con Fecha

Pues nada resulta que tengo la fecha en formato yyyy/mm/dd guardada en la base de datos y quiero mostrarla en formato dd-mm-yyyy. Qué tengo que poner??, ya he probado con el dateformat, date, explode... y nada.

Código PHP:
mysql_select_db($database_BDreservas, $BDreservas);
$query_rs_Reservas = sprintf("SELECT reservas.observaciones as observaciones, reservas.fecha as fecha, profesores.nombre as profesor, seccion.nombre as seccion FROM reservas, profesores, seccion WHERE reservas.fecha BETWEEN %s AND %s AND reservas.id_aulas = %s AND reservas.id_turno = %s AND reservas.id_profesores = profesores.id AND reservas.id_seccion =  seccion.id", 
GetSQLValueString(date("Y-m-d", $fecha_lunes), "date"), 
GetSQLValueString(date("Y-m-d", $fecha_viernes), "date"), 
GetSQLValueString($MM_Aula_rs_Reservas, "int"), 
GetSQLValueString($row_Regasuntocalenturno['id'], "int"));
$rs_Reservas = mysql_query($query_rs_Reservas, $BDreservas) or die(mysql_error());
$row_rs_Reservas = mysql_fetch_assoc($rs_Reservas);
$totalRows_rs_Reservas = mysql_num_rows($rs_Reservas);
?>
    <tr>
      <td><div align="center"><?php echo $row_Regasuntocalenturno['hora']; ?></div></td>
      <td>
          <div align="center">
            <?php
            
if(date("Y-m-d"$fecha_lunes) == $row_rs_Reservas['fecha'])
            {
            
?>
            <form id="form2" name="form2" method="get" action="calendario.php">
            <?php
                
echo $row_rs_Reservas['profesor']."<br />";
                echo 
$row_rs_Reservas['seccion']."<br />";
                echo 
$row_rs_Reservas['observaciones']."<br />";
                echo 
$row_rs_Reservas['fecha']."<br />";
                
$row_rs_Reservas mysql_fetch_assoc($rs_Reservas);
            
?>
Espero vuestra respuesta, muchas gracias antemano.
  #2 (permalink)  
Antiguo 07/05/2008, 08:37
 
Fecha de Ingreso: febrero-2008
Mensajes: 5
Antigüedad: 16 años, 2 meses
Puntos: 0
Re: Problema con Fecha

Hola.
Esta es la funcion ke utilizo yo:

function desql_a_fecha($fecha){
ereg( "([0-9]{1,2})-([0-9]{1,2})-([0-9]{2,4})", $fecha, $mifecha);
$lafecha=$mifecha[3]."/".$mifecha[2]."/".$mifecha[1];
return $lafecha;
}

Un saludo.
  #3 (permalink)  
Antiguo 07/05/2008, 08:41
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Re: Problema con Fecha

Hola xeron,

Para formatear te recomiendo usar strtotime y luego date.

Saludos.
  #4 (permalink)  
Antiguo 07/05/2008, 08:48
 
Fecha de Ingreso: mayo-2008
Mensajes: 10
Antigüedad: 16 años
Puntos: 0
Re: Problema con Fecha

Muchas gracias x responder, voy a probar a ver que tal va la cosa.
  #5 (permalink)  
Antiguo 08/05/2008, 01:43
 
Fecha de Ingreso: mayo-2008
Mensajes: 10
Antigüedad: 16 años
Puntos: 0
Re: Problema con Fecha

Nada. He estado probando pero no se exactamente como aplicarlo (soy algo novato tb)
  #6 (permalink)  
Antiguo 08/05/2008, 04:13
 
Fecha de Ingreso: mayo-2008
Mensajes: 10
Antigüedad: 16 años
Puntos: 0
Re: Problema con Fecha

He estado probando con el date_format que es el que creo mas conveniente para lo que estyo haciendo, lo malo que me da un error Warning: sprintf() [function.sprintf]: Too few arguments in cuando lo ejecuto.

El código queda así.

Código PHP:
<?php
$MM_Aula_rs_Reservas 
"1";
if (isset(
$_GET['aula'])) {
  
$MM_Aula_rs_Reservas = (get_magic_quotes_gpc()) ? $_GET['aula'] : addslashes($_GET['aula']);
}
mysql_select_db($database_BDreservas$BDreservas);
$query_rs_Reservas sprintf("SELECT reservas.observaciones as observaciones, date_format('reservas.fecha', '/%d \/%m \/%Y') as fecha, profesores.nombre as profesor, seccion.nombre as seccion FROM reservas, profesores, seccion WHERE reservas.fecha BETWEEN %s AND %s AND reservas.id_aulas = %s AND reservas.id_turno = %s AND reservas.id_profesores = profesores.id AND reservas.id_seccion =  seccion.id"
GetSQLValueString(date("Y-m-d"$fecha_lunes), "date"), 
GetSQLValueString(date("Y-m-d"$fecha_viernes), "date"), 
GetSQLValueString($MM_Aula_rs_Reservas"int"), 
GetSQLValueString($row_Regasuntocalenturno['id'], "int"));
$rs_Reservas mysql_query($query_rs_Reservas$BDreservas) or die(mysql_error());
$row_rs_Reservas mysql_fetch_assoc($rs_Reservas);
$totalRows_rs_Reservas mysql_num_rows($rs_Reservas);
?>
    <tr>
      <td><div align="center"><?php echo $row_Regasuntocalenturno['hora']; ?></div></td>
      <td>
          <div align="center">
            <?php
            
if(date("Y-m-d"$fecha_lunes) == $row_rs_Reservas['fecha'])
            {
            
?>
            <form id="form2" name="form2" method="get" action="calendario.php">
            <?php
                
echo $row_rs_Reservas['profesor']."<br />";
                echo 
$row_rs_Reservas['seccion']."<br />";
                echo 
$row_rs_Reservas['observaciones']."<br />";
                echo 
$row_rs_Reservas['fecha']."<br />";
                
$row_rs_Reservas mysql_fetch_assoc($rs_Reservas);
            
?>
  #7 (permalink)  
Antiguo 09/05/2008, 01:39
 
Fecha de Ingreso: mayo-2008
Mensajes: 10
Antigüedad: 16 años
Puntos: 0
Re: Problema con Fecha

Por favor! Nadie sabe como hacerlo??
  #8 (permalink)  
Antiguo 09/05/2008, 03:02
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Re: Problema con Fecha

puedes poner en ke linea te salio el error.. o mejor, el mensaje completo...
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 03:13.