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

insertar NOW() en columna tipo DATETIME

Estas en el tema de insertar NOW() en columna tipo DATETIME en el foro de Bases de Datos General en Foros del Web. Hola! Quisiera ver si pueden ayudarme a evacuar la siguiete inquietud: Tebgo una BD MySQL, con una tabla tipo MyISAM y tengo una columna dentro ...
  #1 (permalink)  
Antiguo 14/09/2004, 08:02
 
Fecha de Ingreso: noviembre-2003
Mensajes: 68
Antigüedad: 20 años, 6 meses
Puntos: 0
Pregunta insertar NOW() en columna tipo DATETIME

Hola!
Quisiera ver si pueden ayudarme a evacuar la siguiete inquietud:

Tebgo una BD MySQL, con una tabla tipo MyISAM y tengo una columna dentro de ella, para ingresar datos tipo DATETIME, esta columna es NOT NULL, puesto que la usaré para ordenar cronológicamente un índice de notas publicadas, quisera saber cómo debo escribir el DEFAULT, para que me ingrese la hora actual del servidor por defecto. He probado poniendo NOW(), pero quedan todos los valores en cero: 0000-00-00 00:00:00. También probé poner este valor como NULL (leí en dev.mysql.com que si le das valor nulo a una función de tiempo u hora, esta se registra como el tiempo actual) pero sigue largando todos ceros.
Alguna idea salvadora, colegas?

Desde ya muchas gracias.
__________________
[|_4 (0|\/|U|\|1(4(10|\| 35 |_4 FU3RZ4]
  #2 (permalink)  
Antiguo 14/09/2004, 08:58
Avatar de Funk  
Fecha de Ingreso: septiembre-2003
Ubicación: BA - Argentina
Mensajes: 102
Antigüedad: 20 años, 8 meses
Puntos: 0
Podría armar un formulario de ingreso con el siguiente código, te va a ingresar la fecha y la hora actual.

Codigo:

<?php include ('cnx') ; ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO usuarios3 (ingreso) VALUES (%s)",
GetSQLValueString($HTTP_POST_VARS['ingreso'], "date"));

mysql_select_db($database_cnx_mecca, $cnx_mecca);
$Result1 = mysql_query($insertSQL, $cnx_mecca) or die(mysql_error());
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Ingreso:</td>
<td><input type="text" name="ingreso" value="<?php echo date("Y/m/d H:i:s") ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><input type="submit" value="Insert Record"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>

</body>
</html>
espero te ayude, esto lo probe y funciona

suerte
__________________
Walter Bove
Diseñador Multimedial
Arteuz Comunicación Multimedial
Funk Blog Job
  #3 (permalink)  
Antiguo 14/09/2004, 20:05
 
Fecha de Ingreso: noviembre-2003
Mensajes: 68
Antigüedad: 20 años, 6 meses
Puntos: 0
:-o
wow!
gracias!
eso tendré que leerlo detenidamente.
gracias.
__________________
[|_4 (0|\/|U|\|1(4(10|\| 35 |_4 FU3RZ4]
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 14:15.