Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General »

insertar fecha actual en campo tipo timestamp

Estas en el tema de insertar fecha actual en campo tipo timestamp en el foro de Bases de Datos General en Foros del Web. hola amigos, :) Mi problema :( es que no consigo insertar la fecha actual en uno de los campos de una tabla que tengo. He ...
  #1 (permalink)  
Antiguo 26/07/2002, 06:21
 
Fecha de Ingreso: julio-2002
Mensajes: 28
Antigüedad: 21 años, 9 meses
Puntos: 0
insertar fecha actual en campo tipo timestamp

hola amigos, :)

Mi problema :( es que no consigo insertar la fecha actual en uno de los campos de una tabla que tengo.

He probado con:
$fecha=time();//fecha actual
$insert= "insert into pedidos (fecha_pedido) VALUES (".$fecha."')";

en un campo tipo TIMESTAMP pero lo que me inserta es una ristra de ceros.

¿Cómo he de hacerlo?
¿Y cómo debería de hacerlo para el caso de un campo tipo DATE?.

Muchas gracias por vuestra ayuda. ;) ;)
  #2 (permalink)  
Antiguo 26/07/2002, 06:24
Avatar de Cain  
Fecha de Ingreso: enero-2002
Ubicación: Catalunya
Mensajes: 6.459
Antigüedad: 22 años, 4 meses
Puntos: 17
Re: insertar fecha actual en campo tipo timestamp

1. Eso no es un problema de Base de datos, sino de PHP.
2. Si el campo es TIMESTAMP, introduce un valor TIMESTAMP

Ejemplo:
$avui=date("d/m/Y");
$parts = explode("/", $data_ingres);
$ingres = mktime(0,0,0,$parts[1],$parts[0],$parts[2]);

$ingres sería una fecha en formato TIMESTAMP válido

Joe Tawers,
<a href="http://www.ilimit.com/towers">http://www.ilimit.com/towers</a>
  #3 (permalink)  
Antiguo 26/07/2002, 06:37
 
Fecha de Ingreso: julio-2002
Mensajes: 28
Antigüedad: 21 años, 9 meses
Puntos: 0
Re: insertar fecha actual en campo tipo timestamp

Gracias Cain. Ya me funciona.

;)
  #4 (permalink)  
Antiguo 26/07/2002, 06:40
Avatar de Cain  
Fecha de Ingreso: enero-2002
Ubicación: Catalunya
Mensajes: 6.459
Antigüedad: 22 años, 4 meses
Puntos: 17
Re: insertar fecha actual en campo tipo timestamp

De nada, justo lo aprendí ayer :P

Joe Tawers,
<a href="http://www.ilimit.com/towers">http://www.ilimit.com/towers</a>
  #5 (permalink)  
Antiguo 26/07/2002, 08:27
Avatar de Webstudio
Colaborador
 
Fecha de Ingreso: noviembre-2001
Ubicación: 127.0.0.1
Mensajes: 3.499
Antigüedad: 22 años, 5 meses
Puntos: 69
Re: insertar fecha actual en campo tipo timestamp

disculpame lo que te voy a decir (ya pido disculpas por adelantado, nunca se sabe), pero vos leiste para que sirve un campo TIMESTAMP ?
El campo tipo TIMESTAMP se autoactualiza con el valor de la fecha actual ante un INSERT o un UPDATE, por lo que si modificas el registro, automáticamente se actualiza la fecha.

Saludos.

<hr><font size=2 face=verdana>- Pablo Rigazzi (<img src=http://www.fantabuloso.com/iB_html/non-cgi/emoticons/bullwhip.gif align=absmiddle>)[/CODE]
<font size=1 color=#333333>Visita <a href=http://www.web-studio.com.ar>Web Studio</a>[/CODE]
  #6 (permalink)  
Antiguo 26/07/2002, 08:58
Avatar de Cain  
Fecha de Ingreso: enero-2002
Ubicación: Catalunya
Mensajes: 6.459
Antigüedad: 22 años, 4 meses
Puntos: 17
Re: insertar fecha actual en campo tipo timestamp

Hombre, pero si actualizas el registro indicando un valor timestamp diferente al tiempo actual también lo inserta.

Cita:
The TIMESTAMP column type provides a type that you can use to automatically mark INSERT or UPDATE operations with the current date and time. If you have multiple TIMESTAMP columns, only the first one is updated automatically.

Automatic updating of the first TIMESTAMP column occurs under any of the following conditions:

The column is not specified explicitly in an INSERT or LOAD DATA INFILE statement.
The column is not specified explicitly in an UPDATE statement and some other column changes value. (Note that an UPDATE that sets a column to the value it already has will not cause the TIMESTAMP column to be updated, because if you set a column to its current value, MySQL ignores the update for efficiency.)
You explicitly set the TIMESTAMP column to NULL.
TIMESTAMP columns other than the first may also be set to the current date and time. Just set the column to NULL or to NOW().

You can set any TIMESTAMP column to a value different from the current date and time by setting it explicitly to the desired value. This is true even for the first TIMESTAMP column. You can use this property if, for example, you want a TIMESTAMP to be set to the current date and time when you create a row, but not to be changed whenever the row is updated later
Más información en: <a href='ir.asp?http://www.mysql.com/doc/' target='_blank'>http://www.mysql.com/doc/...</a>
  #7 (permalink)  
Antiguo 26/07/2002, 09:07
 
Fecha de Ingreso: julio-2002
Mensajes: 28
Antigüedad: 21 años, 9 meses
Puntos: 0
Re: insertar fecha actual en campo tipo timestamp

No hacía falta que te disculparas Webstudio. :)

Eso que has comentado es una cosa que yo, por lo menos, no sabía.
Como veis estoy bastante &quot;verde&quot; en esto del PHP, y no tengo mucho tiempo para aprender jeje.

Saludos a todos. :)
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

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 04:19.