Problema con formato de fecha

18/05/2004 - 20:13 por Maite | Informe spam
Hola a todos!

Estoy teniendo un problema y ya no se como solucionarlo. En un formulario
entro una fecha, recojo esa fecha y la guardo en una base de datos. Pues el
problema es q si pongo la siguiente fecha "12/05/2004" me guarda
"05/12/2004", cuando el día és mayor que el número de meses no me lo hace
("13/05/2004").

Alguien me podría decir que me está pasando y la solución??

Graciasssssssssssssssssss

Preguntas similare

Leer las respuestas

#1 GONZALO SKARMETA
18/05/2004 - 22:20 | Informe spam
Revisa si el formato de las fechas del Servidor de Datos
y el Servidor del Sistema Operativo sean iguales.

si la base de datos es Oracle prueba con el siguiente
codigo:

dDate = formatdatetime(Date())
dMonth = Month(dDate)
dDay = day(dDate)
dYear = year(dDate)
fecha = dDay & "/" & dMonth & "/" & dYear

al guardarla tienes que dejarla en el siguiente formato:
to_date('" & fecha & "','dd/mm/yyyy')


Ojala te sirva.

Saludos.

Mostrar la cita
En un formulario
Mostrar la cita
base de datos. Pues el
Mostrar la cita
me guarda
Mostrar la cita
meses no me lo hace
Mostrar la cita
solución??
Mostrar la cita
#2 Gabriel South
19/05/2004 - 05:41 | Informe spam
Si el formato es access o ms-Sql

Si el servidor de BD esta configurado con formato de fecha mm/dd/aaaa una
buena forma de solucionar ese problema es hacer lo siguiente:

Al guardar un campo fecha, guardarlas en formato aaaa/mm/dd que es universal

Al recuperar las fechas, normalmente la variable te va a quedar cargada con
el formato en que esta configurado el servidor de bases de datos Si
sabes de antemano por ej. que el formato es mm/dd/aaaa puedes hacer una
funcion que invierta ell mm/dd por dd/mm solo para mostrar el campo.

Yo lo uso asi y me funciona siempre

Suerte


"GONZALO SKARMETA" escreveu na
mensagem news:eca801c43d15$92f69e60$
Revisa si el formato de las fechas del Servidor de Datos
y el Servidor del Sistema Operativo sean iguales.

si la base de datos es Oracle prueba con el siguiente
codigo:

dDate = formatdatetime(Date())
dMonth = Month(dDate)
dDay = day(dDate)
dYear = year(dDate)
fecha = dDay & "/" & dMonth & "/" & dYear

al guardarla tienes que dejarla en el siguiente formato:
to_date('" & fecha & "','dd/mm/yyyy')


Ojala te sirva.

Saludos.

Mostrar la cita
En un formulario
Mostrar la cita
base de datos. Pues el
Mostrar la cita
me guarda
Mostrar la cita
meses no me lo hace
Mostrar la cita
solución??
Mostrar la cita
#3 principiante
20/05/2004 - 22:11 | Informe spam
como primer linea en tus paginas asp coloca
<%@LCID34%>
para que en pantallas uses dd/mm/aaaa y aun persiste te
aconsejo que siempre recuperes la fecha por dia,mes y año
por separado para evitar confusiones. a continuación te
paso dos codigos espero te sirvan
main.asp
calenadrio.asp
son ejemplos de llamada a fecha y evitar validaciones y
errores, cuando guardo lo hago asi:
update stabla set fecha='" & sfecha & "'"


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0
Transitional//EN">
<HTML>
<HEAD>
<TITLE>Main Parent Window</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<%
vbvariable = request.querystring("testvariable")
vbvariable = "Hola"
%>

<SCRIPT LANGUAGE="JavaScript">
// Global variables
var winModalWindow;

function ShowWin1(xfecha) {
if (window.showModalDialog) {
rv = window.showModalDialog("calendario.asp?
xfecha="+xfecha,null,"dialogWidth00px;dialogHeight50px
;status:no");
if (rv!=undefined)
if ((datos.sfechaini.value!=rv) &&
(datos.sfechaini.length!=0))
datos.sfechaini.value = rv; // we hope for a
color here in this example.
}
}

function ShowWin2(xfecha) {
if (window.showModalDialog) {
rv = window.showModalDialog("calendario.asp?
xfecha="+xfecha,null,"dialogWidth00px;dialogHeight50px
;status:no");
if (rv!=undefined)
if ((datos.sfechafin.value!=rv) &&
(datos.sfechafin.length!=0))
datos.sfechafin.value = rv; // we hope for a
color here in this example.
}
}


function showVBcode() {
var test1 = "some string here ";
newvariable = test1 + '<%=vbvariable%>';
alert(newvariable);
}
</SCRIPT>
</HEAD>

<BODY>
<form name="datos" action="Main.asp" method="post"
target="self">
<p>ShowModal and Quasi ShowModal simple dialog
example : <BR>
<BR>
fecha de registro
<input type="text" name="sfechaini" readonly value="<%
=sfechaini%>">
<a href="javascript:ShowWin1
(datos.sfechaini.value);"><img src="icons/date.gif"
width="19" height="20" border="0"></a>
</p>
<p>otro campo
<input type="text" name="textfield" onBlur="showVBcode
();">
<p>fecha de entrega
<input type="text" name="sfechafin" readonly value="<%
=sfechafin%>">
<a href="javascript:ShowWin2
(datos.sfechafin.value);"><img src="icons/date.gif"
width="19" height="20" border="0"></a>
<p>&nbsp;
</form>
</BODY>
</HTML>



y el otro es:



<%@ Language=VBScript %>
<%
'pagina que recibirá la fecha seleccionada por el usuario
Const URLDestino = "window.history.go(-1);"

Dim MyMonth 'Month of calendar
Dim MyYear 'Year of calendar
Dim FirstDay 'First day of the month. 1 = Monday
Dim CurrentDay 'Used to print dates in calendar
Dim Col 'Calendar column
Dim Row 'Calendar row
Dim sfecha
sfecha=Request.QueryString("xfecha")
MyMonth = Request.Querystring("Month")
MyYear = Request.Querystring("Year")
' response.write "fecha anterior:" & sfecha
If Not IsDate(sfecha) Then
sfecha=date
End If
If IsEmpty(MyMonth) then MyMonth = Month(sfecha)
If IsEmpty(MyYear) then MyYear = Year(sfecha)
Call ShowHeader (MyMonth, MyYear)
FirstDay = WeekDay(DateSerial(MyYear, MyMonth, 1)) -1
CurrentDay = 1

'Let's build the calendar
For Row = 0 to 5
For Col = 0 to 6
If Row = 0 and Col < FirstDay then
response.write "<td>&nbsp;</td>"
elseif CurrentDay > LastDay(MyMonth,
MyYear) then
response.write "<td>&nbsp;</td>"
else
response.write "<td"
if cInt(MyYear) = Year(sfecha)
and cInt(MyMonth) = Month(sfecha) and CurrentDay = Day
(sfecha) then
response.write "
class='calCeldaResaltado' align='center'>"
else
response.write "
align='center'>"
end if
response.write "<button onclick='CloseModal("
& CurrentDay & "," & MyMonth & "," & MyYear & ");'>" &
CurrentDay & "</button>"
if cInt(MyYear) = Year(sfecha)
and cInt(MyMonth) = Month(sfecha) and CurrentDay = Day
(sfecha) then
Response.Write "<div
class='calResaltado'>"
else
Response.Write "<div
class='calSimbolo'>"
end if
Response.Write "</div></td>"
CurrentDay = CurrentDay + 1
End If
Next
response.write "</tr>"
Next
response.write "</table>"
response.write "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<butto
n onclick='CloseNull();'>Ninguna</button> "
response.write "<button onclick='self.close
()'>Cerrar</button>" & "</body></html>"


' Sub and functions


Sub ShowHeader(MyMonth,MyYear)
%>
<html>
<title> * Calendario * </title>
<head>
<meta http-equiv='Content-Type'
content='text/html; charset=iso-8859-1'>
<base TARGET="_self">
<style>
.calFondoCalendario {background-
color:blue}
.calEncabe {font-family:Arial, Helvetica,
sans-serif; font-size:11px}
.calFondoEncabe {background-color:red}
.calDias {font-family:Arial Bold,
Helvetica, sans-serif; font-size:9px; font-weight:900;
color:yellow}
.calSimbolo {font-family:Arial,
Helvetica, sans-serif; font-size:11px; text-
decoration:none; font-weight:200; color:white}
.calResaltado {font-family:Arial,
Helvetica, sans-serif; font-size:11px; text-
decoration:none; font-weight:700}
.calCeldaResaltado {background-
color:white}
</style>

<script language="javascript">

function CloseModal(sdia,smes,sanio)
{
// IE type browser
if (!window.opener) {
sfecha=sdia+"/"+smes+"/"+sanio
window.returnValue = sfecha;
}
window.close();
}

function CloseNull()
{
// IE type browser
if (!window.opener) {
window.returnValue = "";
}
window.close();
}

</script>
</head>

<body bgcolor='#FFFFFF'>
<table border='1' cellspacing='3' cellpadding='3'
width='200' align='center' class='calFondoCalendario'>
<tr align='center'>
<td colspan='7'>
<table border='0' cellspacing='1'
cellpadding='1' width='100%' class="calFondoEncabe">
<tr>
<td align='left'>
<%

response.write "<a href = 'calendario.asp?"
if
MyMonth - 1 = 0 then

response.write "month&year=" & MyYear -1
else

response.write "month=" & MyMonth - 1 & "&year="
& MyYear
end if

response.write "'><span
class='calSimbolo'><<</span></a>"


response.write "<span class='calEncabe'> <b>" &
MonthName(MyMonth) & "</b> </span>"


response.write "<a href = 'calendario.asp?"
if
MyMonth + 1 = 13 then

response.write "month=1&year=" & MyYear + 1
else

response.write "month=" & MyMonth + 1 & "&year="
& MyYear
end if

response.write "'><span
class='calSimbolo'>>></span></a>"
%>
</td>
<td
align='center'>
<%

response.write "<a href = 'calendario.asp?"

response.write "month=" & Month(date) & "&year="
& Year(date)

response.write "'><div
class='calSimbolo'><b>Hoy</b></div></a>"
%>

</td>
<td align='right'>
<%

response.write "<a href = 'calendario.asp?"

response.write "month=" & MyMonth & "&year=" &
MyYear -1

response.write "'><span
class='calSimbolo'><<</span></a>"


response.write "<span class='calEncabe'> <b>" &
MyYear & "</b> </span>"

response.write "<a href = 'calendario.asp?"

response.write "month=" & MyMonth & "&year=" &
MyYear + 1

response.write "'><span
class='calSimbolo'>>></span></a>"
%>
</td>
</tr>
</table>
</td>
</tr>
<tr align='center'>
<td><div class='calDias'>D</div></td>
<td><div class='calDias'>L</div></td>
<td><div class='calDias'>M</div></td>
<td><div class='calDias'>Mi</div></td>
<td><div class='calDias'>J</div></td>
<td><div class='calDias'>V</div></td>
<td><div class='calDias'>S</div></td>
</tr>
<%
End Sub

Function MonthName(MyMonth)
Select Case MyMonth
Case 1
MonthName = "Enero"
Case 2
MonthName = "Febrero"
Case 3
MonthName = "Marzo"
Case 4
MonthName = "Abril"
Case 5
MonthName = "Mayo"
Case 6
MonthName = "Junio"
Case 7
MonthName = "Julio"
Case 8
MonthName = "Agosto"
Case 9
MonthName = "Septiembre"
Case 10
MonthName = "Octubre"
Case 11
MonthName = "Noviembre"
Case 12
MonthName = "Diciembre"
Case Else
MonthName = "ERROR!"
End Select
End Function

Function LastDay(MyMonth, MyYear)
' Returns the last day of the month. Takes into account
leap years
' Usage: LastDay(Month, Year)
' Example: LastDay(12,2000) or LastDay(12) or Lastday


Select Case MyMonth
Case 1, 3, 5, 7, 8, 10, 12
LastDay = 31

Case 4, 6, 9, 11
LastDay = 30

Case 2
If IsDate(MyYear & "-" & MyMonth
& "-" & "29") Then LastDay = 29 Else LastDay = 28

Case Else
LastDay = 0
End Select
End Function
%>
Ads by Google
Search Busqueda sugerida