![]() |
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. |
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"> </td> <td><input type="submit" value="Insert Record"></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1"> </form> <p> </p> </body> </html> espero te ayude, esto lo probe y funciona suerte |
:-o wow! gracias! eso tendré que leerlo detenidamente. gracias. |
| La zona horaria es GMT -6. Ahora son las 19:10. |
Desarrollado por vBulletin® Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.