Retroceder   Foros del Web > Programación para sitios web > Bases de Datos

Respuesta
 
Herramientas Desplegado
Antiguo 14-sep-2004, 08:02   #1 (permalink)
5H1V4 ha deshabilitado el karma
 
Fecha de Ingreso: noviembre-2003
Mensajes: 68
Enviar un mensaje por Yahoo  a 5H1V4
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]
5H1V4 está desconectado   Responder Citando
Antiguo 14-sep-2004, 08:58   #2 (permalink)
Funk ha deshabilitado el karma
 
Avatar de Funk
 
Fecha de Ingreso: septiembre-2003
Ubicación: BA - Argentina
Mensajes: 92
Enviar un mensaje por ICQ a Funk Enviar un mensaje por MSN a Funk
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
__________________
|FUNK| :cool:
Diseñador Multimedial
Arteuz Multimedia Studio
www.arteuz.com.ar
Funk Blog Job
Funk está desconectado   Responder Citando
Antiguo 14-sep-2004, 20:05   #3 (permalink)
5H1V4 ha deshabilitado el karma
 
Fecha de Ingreso: noviembre-2003
Mensajes: 68
Enviar un mensaje por Yahoo  a 5H1V4
:-o
wow!
gracias!
eso tendré que leerlo detenidamente.
gracias.
__________________
[|_4 (0|\/|U|\|1(4(10|\| 35 |_4 FU3RZ4]
5H1V4 está desconectado   Responder Citando
Respuesta

No hay votos aún.


Herramientas
Desplegado

Normas de Publicación
No puedes crear nuevos temas
No puedes responder temas
No puedes subir archivos adjuntos
No puedes editar tus mensajes

BB code is Activado
Caritas están Activado
[IMG] está Activado
Código HTML está Desactivado


La Zona horaria es GMT -6. Ahora son las 21:21.


Message Board Statistics

LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93