Foros del Web » Programando para Internet » ASP Clásico »

Problemas Con Fechas En Sql Server

Estas en el tema de Problemas Con Fechas En Sql Server en el foro de ASP Clásico en Foros del Web. Hola. Necesito Informacion Acerca De Como Insertar Fechas Pasadas Por Formularios Con Asp A Sql Server. Sucede Que La Estoy Pasando Por String Y No ...
  #1 (permalink)  
Antiguo 20/09/2004, 08:42
Avatar de verinchi  
Fecha de Ingreso: septiembre-2004
Ubicación: Buenos Aires
Mensajes: 647
Antigüedad: 19 años, 8 meses
Puntos: 2
Pregunta Problemas Con Fechas En Sql Server

Hola.
Necesito Informacion Acerca De Como Insertar Fechas Pasadas Por Formularios Con Asp A Sql Server. Sucede Que La Estoy Pasando Por String Y No Tira Errores, Pero Lo Que Muestra Como Fecha Actual El Sql Me Lo Toma Como 01/01/1900, Contrariedad Bastante Grande!!!
La Forma En Que La Tomo Es La Mas Simple:
Fechai=request.form("fecha") Que Es La De Origen, El Insert Lo Ejecuto Con Un Comando Con Sentencia Sql Dandole A La Columna Fecha De La Tabla El Valor Fechai

Si Alguien Tiene Una Idea De Que Es Lo Que Pasa Y Puede Ayudarme Se Lo Agradeceria
  #2 (permalink)  
Antiguo 20/09/2004, 08:45
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
y si en el insert le coloca now() o time() ????

ejemplo:
insert into tabla(fecha) values ('" now() & "')
no se si esto es lo que quieres hacer y si no, explicate un poco mas

saludos
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #3 (permalink)  
Antiguo 20/09/2004, 08:56
Avatar de verinchi  
Fecha de Ingreso: septiembre-2004
Ubicación: Buenos Aires
Mensajes: 647
Antigüedad: 19 años, 8 meses
Puntos: 2
No, En Realidad No Quiero Hacer Eso, Porque La Fecha Debe Poder Ser Ingresada Por El Usuario, Ese Es Mi Problema
  #4 (permalink)  
Antiguo 20/09/2004, 09:07
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 22 años, 4 meses
Puntos: 146
mmm, bueno, dos cosas:

Primero define el LCID (http://www.webwizguide.info/asp/faq/...e_settings.asp) que te corresponda.

Puedes "acomodar" la fecha separandola previamente, concatenándola y enviandosela al SQL en el formato que el espere mediante las funciones DAY(), MONTH() y YEAR()

Saludos
  #5 (permalink)  
Antiguo 20/09/2004, 09:08
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
pero porque mejor no pones el input como readonly y le pones un botonsito al lado que llame un popup con un calendario.. se veria mas cool
asi es como lo tengo yo... como me dice mi jefe: "hay que programar a prueba de estupidos"

en los fags de javascript hay ejemplo de calendarios... si no encunentras ninguno te mando el mio ok?
saludos
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #6 (permalink)  
Antiguo 20/09/2004, 09:15
Avatar de verinchi  
Fecha de Ingreso: septiembre-2004
Ubicación: Buenos Aires
Mensajes: 647
Antigüedad: 19 años, 8 meses
Puntos: 2
Gracias!! Me Interesaria Que Me Enviases El Script Para El Calendario, No Para Este Proyecto Porque Es Soft De Manejo Interno Y Si Les Digo Que Programo Para Estupidos Se Van A Enojar!!!! Pero Me Intereso Mucho El Tema Del Calendario En Popup, Me Parece Una Opcion Inteligente Para Otras Aplicaciones!!!! Voy A Probar Con La Opcion De Separar La Fecha Para Este Caso Y En Cualquier Eventualidad Aviso.
Muchisimas Gracias!!!!
  #7 (permalink)  
Antiguo 20/09/2004, 09:27
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 22 años, 4 meses
Puntos: 146
Cita:
Iniciado por Saruman
... como me dice mi jefe: "hay que programar a prueba de estupidos"
Una vez tuve un maestro que para probar los sistemas (En DOS) apretaba todas las teclas a ver si se inhibia la máquina, jejejeje. Me acorde de ese profesor, jejeje
  #8 (permalink)  
Antiguo 20/09/2004, 09:32
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
ok, aqui esta el calendario:

default.asp

Código:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Calendario</title>
</head>

<script language="javascript">
	function CalPop(sInputName) {
		window.open('calendario.asp?objeto=' + escape(sInputName) + '&initialDate=' + escape(window.eval(sInputName).value), 'CalPop', 'toolbar=0,width=180,height=190');
	}
</script>

<body>

<form name="form1" method="post" action="">
<table width="50%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
	<td width="46%"><input name="txtfecha_usuario" type="text" size="12" maxlength="20" value="" readonly style="text-align:center"></td>
	<td><input type="button" name="Button" value="F" onClick="CalPop('document.form1.txtfecha_usuario')"></td>
  </tr>
</table>
</form>

</body>
</html>

calendario.asp

Código:
<html> 
<title>Calendario</title>
<head> 

<%
	objeto = request.QueryString("objeto")
	initialDate = request.QueryString("initialDate")
%>

  <script language="JavaScript"> 

   var fecha_nueva = "<%=(initialDate)%>";
   if (fecha_nueva != "") {
   	  var dFec = new Date(fecha_nueva);
   } else {
   	  var dFec = new Date();
   }
   var aMonthNames = new Array( 
                          "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", 
                          "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"); 

   function firstOfMonth(dFec){ 
    var dRes = new Date(); 
    dRes.setYear(dFec.getYear()); 
    dRes.setMonth(dFec.getMonth()); 
    dRes.setDate(1); 
    return dRes; 
   } 

   function lastDayOfMonth(dFec){ 
    var dRes = new Date(); 
    var nYear = dFec.getYear(); 
    var nMonth = dFec.getMonth() + 1; 
    if (nMonth == 12){ 
     nMonth = 0; 
     nYear++; 
    } 
    dRes.setYear(nYear); 
    dRes.setMonth(nMonth); 
    dRes.setDate(1); 
    return new Date(dRes.valueOf() - (24 * 60 * 60 * 1000)); 
   } 

   function dayToWrite(nDay){ 
    var dToday = new Date(); 
    var bisThisMonth = ((dFec.getYear() == dToday.getYear()) || (dFec.getMonth() == dToday.getMonth())); 
    var sDay = String(nDay); 
    sDay = (nDay == dFec.getDate() && bisThisMonth? "<b><font color='red'>" + sDay + "</font></b>": sDay);
    return sDay; 
   } 

   function selectDay(nDay){ 
    var sRes, sDay, sMon, sYea; 
    sDay = "0" + String(nDay); 
    sDay = sDay.substr(sDay.length - 2, 2); 
    sMon = "0" + String(dFec.getMonth() + 1); 
    sMon = sMon.substr(sMon.length - 2, 2); 
    sYea = String(dFec.getFullYear()); 
    sRes = sMon + "/" + sDay + "/" + sYea;
	window.opener.eval("<%=(objeto)%>").value = sRes;
    //opener.fillDateField();  llamando una funcion
    close(); 
   } 

   function showCalenContents() { 
    var dFec0 = firstOfMonth(dFec); 
    var nDay = 1; 
    var nLastDay = lastDayOfMonth(dFec).getDate(); 
    var sWeek = ""; 
    var bEnd = false; 
    var bWri = false; 
    var nDOW0 = dFec0.getDay(); 
    for (var j = 0; !bEnd; j++){ 
     sWeek = "<tr>"; 
     for (var i = 0; (i < 7) && !bEnd; i++){ 
      bWri = bWri || (i == nDOW0); 
      if (bWri) 
       sWeek += "<td align='right' title='Click para Insertar' style='text-align:center; border:1px solid #646464; cursor: hand;' onclick='parent.selectDay(" + String(nDay) + ")'>" + dayToWrite(nDay, bWri) + "</td>"; 
      else 
       sWeek += "<td>&nbsp;</td>"; 
      if (bWri) nDay++; 
      bEnd = (nDay > nLastDay); 
     } 
     if (bEnd) 
      for (var k = i; k < 7; k++) 
       sWeek = sWeek + "<td>&nbsp;&nbsp;</td>"; 
     window.usefull.document.writeln(sWeek + "</tr>"); 
    } 
   } 

   function backMonth(){ 
    var nMonth = dFec.getMonth(); 
    var nYear = dFec.getFullYear(); 
    if (--nMonth == -1){ 
     nMonth = 11; 
     nYear--; 
    } 
    dFec.setMonth(nMonth); 
    dFec.setYear(nYear); 
    calendary(); 
   } 

   function forthMonth(){ 
    var nMonth = dFec.getMonth(); 
    var nYear = dFec.getFullYear(); 
    if (++nMonth == 12){ 
     nMonth = 0; 
     nYear++; 
    } 
    dFec.setMonth(nMonth); 
    dFec.setYear(nYear); 
    calendary(); 
   } 

   function backYear(){ 
    var nYear = dFec.getFullYear(); 
    dFec.setYear(--nYear); 
    calendary(); 
   } 

   function forthYear(){ 
    var nYear = dFec.getFullYear(); 
    dFec.setYear(++nYear); 
    calendary(); 
   } 

   function showCalen(){ 
    with (window.usefull.document){ 
     write("<table border='0' width='100%' height='100%'><tr><td><table border='0' width='100%' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color:#000000;'><tr>"); 
     write("<td width='10'><input title='A&ntilde;o Anterior' type='button' name='bckYear' value='««' onclick='parent.backYear()' style='border-left:1px solid #C0C0C0; border-top:1px solid #C0C0C0; border-right:1px solid #292929; border-bottom:1px solid #292929; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color:#000000; font-weight:bold'></td>"); 
     write("<td width='10'><input title='Mes Anterior' type='button' name='bckMonth' value='«' onclick='parent.backMonth()' style='border-left:1px solid #C0C0C0; border-top:1px solid #C0C0C0; border-right:1px solid #292929; border-bottom:1px solid #292929; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color:#000000; font-weight:bold'></td>"); 
     write("<td align='center'><b>" + aMonthNames[dFec.getMonth()].substr(0, 3) + ", " + String(dFec.getYear()) + "</b></td>"); 
     write("<td width='10'><input title='Mes Siguiente' type='button' name='ForMonth' value='»' onclick='parent.forthMonth()' style='border-left:1px solid #C0C0C0; border-top:1px solid #C0C0C0; border-right:1px solid #292929; border-bottom:1px solid #292929; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color:#000000; font-weight:bold'></td>"); 
     write("<td width='10'><input title='A&ntilde;o Siguiente' type='button' name='ForYear' value='»»' onclick='parent.forthYear()' style='border-left:1px solid #C0C0C0; border-top:1px solid #C0C0C0; border-right:1px solid #292929; border-bottom:1px solid #292929; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color:#000000; font-weight:bold'></td>"); 
     write("</tr></table></tr><tr><td valign='top'>"); 
     write("<table border='0' align='center' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color:#000000;'>"); 
     write("<tr style='text-align:center;'><td width='5%'><b>Do</b></td><td width='5%'><b>Lu</b></td><td width='5%'><b>Ma</b></td><td width='5%'><b>Mie</b></td><td width='5%'><b>Jue</b></td><td width='5%'><b>Vi</b></td><td width='5%'><b>Sa</b></td></tr>"); 
     showCalenContents(); 
     write("</table></td></tr></table>"); 
    } 
   } 

   function calendary(){ 
    with (window.usefull.document){ 
     open(); 
     writeln("<html><head></head><body>"); 
     writeln("<form name='frm'>"); 
     showCalen(); 
     writeln("</form></body></html>"); 
     close(); 
    } 
   } 

  </script> 
<head> 
<frameset rows="100%,*" border="0" frameborder="no" framespacing="0" onload="calendary()"> 
  <frame name="usefull" src="DummyPg.htm" frameborder="no" marginheight="0" marginwidth="0" scrolling="no"> 
  <frame name="useless" src="DummyPg.htm" frameborder="no" marginheight="0" marginwidth="0" scrolling="no"> 
</frameset><noframes></noframes> 
<html>
dummypg.htm

Código HTML:
<html> 
<head> 
</head> 
<body> 
</body> 
</html> 

guarda estos tres archivos, pruebalos y me dices....
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #9 (permalink)  
Antiguo 20/09/2004, 10:04
Avatar de Myakire
Colaborador
 
Fecha de Ingreso: enero-2002
Ubicación: Centro de la república
Mensajes: 8.849
Antigüedad: 22 años, 4 meses
Puntos: 146
vaya, vaya, vaya excelente tu aporte

Funciona muy bien
  #10 (permalink)  
Antiguo 20/09/2004, 10:06
Avatar de Saruman  
Fecha de Ingreso: mayo-2003
Ubicación: Panama city, Panama, Panama
Mensajes: 1.154
Antigüedad: 21 años
Puntos: 5
me alegra
__________________
Saruman

One Ring to rule them all, One Ring to find them, One Ring to bring them all and in the darkness bind them.
  #11 (permalink)  
Antiguo 20/09/2004, 11:21
Avatar de verinchi  
Fecha de Ingreso: septiembre-2004
Ubicación: Buenos Aires
Mensajes: 647
Antigüedad: 19 años, 8 meses
Puntos: 2
Sigo Con Problemas Para Ingresar La Fecha, Ya ComprobÉ Con Una Pagina Auxiliar Que La Fecha Que Le Paso Al Sql Sea Por Form, Como Con Funciones Y Concatenando Se Encuentra Correcta, Pero Al Momento De Ingresar En La Tabla Genera Enero De 1900...., El Formato De Fecha Del Campo De La Tabla Es Datetime... Al Ingresar Manualmente Los Valores Los Toma Como Dd/mm/yyyy Y Es Asi Como Le Paso Los Valores Desde El Form!
Ahora Si Que Me Veo En Problemas Graves!!!
  #12 (permalink)  
Antiguo 20/09/2004, 11:34
Avatar de Muzztein  
Fecha de Ingreso: agosto-2002
Ubicación: Hangar 18
Mensajes: 1.703
Antigüedad: 21 años, 9 meses
Puntos: 16
Malditas fechas!!!

jeje...

bueno.para empezar debes chequear en que idioma esta el web server y en que idioma esta la base de datos.

si la base de datos esta en ingles, siempre esperará la fecha en formato mmddaa. y si se la pasas en formato ddmmaa arrojara un error.

Asi es que tienes que sintonizar en la misma frecuencia al web server y a la base de datos.

ademas recuerda que en el string sql a ejecutar, las fechas deben estar rodeadas por comillas simples.

y eso.
  #13 (permalink)  
Antiguo 20/09/2004, 12:23
Avatar de verinchi  
Fecha de Ingreso: septiembre-2004
Ubicación: Buenos Aires
Mensajes: 647
Antigüedad: 19 años, 8 meses
Puntos: 2
POR LO DE SINTONIZAR LOS TIPOS DE LA PAG Y EL SISTEMA ESTAN EN ORDEN.
AHORA VOY COMPRENDIENDO MI PROBLEMA, HACIENDO CASO A TU CONSEJO ME TIRA
EL ERROR '[Microsoft][ODBC SQL Server Driver][SQL Server]Error de sintaxis al convertir una cadena de caracteres a datetime.
LA PREGUNTA ES: HABRA UNA FUNCION QUE ME PERMITA PASAR UN STIRNG A DATETIME???
YO LO INTENTE APLICANDOLES LAS FUNCIONES MES DIA Y AÑO COMO SÑALO ARRIBA, Y DESPUES LAS CONCATENE DE ESTA FORMA FINAL=DIA&MES&ANIO
CUAL SERIA EL ERROR?
  #14 (permalink)  
Antiguo 21/09/2004, 00:31
 
Fecha de Ingreso: julio-2002
Mensajes: 447
Antigüedad: 21 años, 10 meses
Puntos: 0
Hola, probá de ingresar las fechas de esta forma:

AAAA/MM/DD

Yo lo uso así y me funciona siempre bien sin importar las configuraciones, no se confunde nunca.
Saludos, suerte
  #15 (permalink)  
Antiguo 27/09/2004, 06:43
Avatar de Muzztein  
Fecha de Ingreso: agosto-2002
Ubicación: Hangar 18
Mensajes: 1.703
Antigüedad: 21 años, 9 meses
Puntos: 16
buena idea la del "che".

La funcion que transfroma a fecha un string es cdate(), y la funcion que valida que sea una fecha es isdate()

por ejemplo :

fecha = cdate(now)
if isdate(fecha) = true then
'el string es una fecha
else
'el string no es una fecha
end if

o algo asi ;)
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 02:11.