Foros del Web » Programando para Internet » Javascript »

Agregar Un 0 Al Mes 1 De Un Calendario?

Estas en el tema de Agregar Un 0 Al Mes 1 De Un Calendario? en el foro de Javascript en Foros del Web. Hola a todos: Tengo un problema, tengo un calendario que esta hecho en Javascript, pero me muestra la fecha asì (año-mes-dia)2004-6-1 y yo necesito que ...
  #1 (permalink)  
Antiguo 21/06/2004, 10:07
 
Fecha de Ingreso: abril-2004
Ubicación: Aguascalientes
Mensajes: 65
Antigüedad: 20 años
Puntos: 0
Pregunta Agregar Un 0 Al Mes 1 De Un Calendario?

Hola a todos:

Tengo un problema, tengo un calendario que esta hecho en Javascript, pero me muestra la fecha asì (año-mes-dia)2004-6-1 y yo necesito que me muestre el 0 (año-mes-dia)2004-06-01, mi pregunta es como le puedo agregar el 0 al mes y al dìa?... Este script lo uso en php, y la BD esta en MySql...

este es el script del calendario:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0046)http://homepage.tinet.ie/~johncasey/popcjs.htm -->
<!-- saved from url=(0053)http://javascripts.earthweb.com/repository/popcjs.htm --><HTML><HEAD><TITLE>Untitled</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1170" name=GENERATOR></HEAD>
<BODY leftMargin=0 topMargin=0>
<SCRIPT language=JScript>
<!-- Begin //place these scripts within BODY tag if you are using IE 4.0 or below.
//************************************************** **************************
// PopCalendar 4.1, Emailware(please mail&commend me if u like it)
// Originally coded by Liming(Victor) Weng, email: [email protected]
// Release date: 2000.5.9
// Anyone may modify it to satify his needs, but please leave this comment ahead.
//************************************************** **************************

var gdCtrl = new Object();
var gcGray = "#808080";
var gcToggle = "#ffff00";
var gcBG = "#cccccc";

var gdCurDate = new Date();
var giYear = gdCurDate.getFullYear();
var giMonth = gdCurDate.getMonth()+1;
var giDay = gdCurDate.getDate();
var VicPopCal = new Object();

//************************************************** **************************
// Param: popCtrl is the widget beyond which you want this calendar to appear;
// dateCtrl is the widget into which you want to put the selected date;
// popCal is the widget to display the calendar;
// i.e.: <input type="text" name="dc" style="text-align:center" readonly><INPUT type="button" value="V" onclick="fPopCalendar(dc,dc,popCal);return false">
//************************************************** **************************
function fPopCalendar(popCtrl, dateCtrl, popCal){
parent.event.cancelBubble=true;
VicPopCal = popCal;
gdCtrl = dateCtrl;
fSetYearMon(giYear, giMonth);
var point = fGetXY(popCtrl);
with (VicPopCal.style) {
left = point.x;
top = point.y+popCtrl.offsetHeight+1;
visibility = 'visible';
}
VicPopCal.focus();
// in order to make compatible with IE4.x , here I cut two line below off.
// VicPopCal.all("popFrame").width=document.all("popT able").offsetWidth;
// VicPopCal.all("popFrame").height=document.all("pop Table").offsetHeight;
// if u only target on IE5.x, uncommented them and delete the width&height prop in <IFrame> tag
// thus you will find the 3rd para in fDrawCal() now works perfectly.
}

function fSetDate(iYear, iMonth, iDay){
gdCtrl.value = iYear+"-"+iMonth+"-"+iDay; //Here, you could modify the locale as you need !!!!
VicPopCal.style.visibility = "hidden";
}

function fSetSelected(aCell){
var iOffset = 0;
var iYear = parseInt(tbSelYear.value);
var iMonth = parseInt(tbSelMonth.value);

aCell.bgColor = gcBG;
with (aCell.children["cellText"]){
var iDay = parseInt(innerText);
if (color==gcGray)
iOffset = (Victor<10)?-1:1;
iMonth += iOffset;
if (iMonth<1) {
iYear--;
iMonth = 12;
}else if (iMonth>12){
iYear++;
iMonth = 1;
}
}
fSetDate(iYear, iMonth, iDay);
}

function Point(iX, iY){
this.x = iX;
this.y = iY;
}

function fBuildCal(iYear, iMonth) {
var aMonth=new Array();
for(i=1;i<7;i++)
aMonth[i]=new Array(i);

var dCalDate=new Date(iYear, iMonth-1, 1);
var iDayOfFirst=dCalDate.getDay();
var iDaysInMonth=new Date(iYear, iMonth, 0).getDate();
var iOffsetLast=new Date(iYear, iMonth-1, 0).getDate()-iDayOfFirst+1;
var iDate = 1;
var iNext = 1;

for (d = 0; d < 7; d++)
aMonth[1][d] = (d<iDayOfFirst)?-(iOffsetLast+d):iDate++;
for (w = 2; w < 7; w++)
for (d = 0; d < 7; d++)
aMonth[w][d] = (iDate<=iDaysInMonth)?iDate++iNext++);
return aMonth;
}

function fDrawCal(iYear, iMonth, iCellWidth, iDateTextSize) {
var WeekDay = new Array("Do","Lu","Ma","Mi","Ju","Vi","Sa");
var styleTD = " bgcolor='"+gcBG+"' width='"+iCellWidth+"' bordercolor='"+gcBG+"' valign='middle' align='center' style='font:bold "+iDateTextSize+" Courier;"; //Coded by Liming Weng(Victor Won) email:[email protected]

with (document) {
write("<tr>");
for(i=0; i<7; i++)
write("<td "+styleTD+"color:#990099' >" + WeekDay[i] + "</td>");
write("</tr>");

for (w = 1; w < 7; w++) {
write("<tr>");
for (d = 0; d < 7; d++) {
write("<td id=calCell "+styleTD+"cursor:hand;' onMouseOver='this.bgColor=gcToggle' onMouseOut='this.bgColor=gcBG' onclick='fSetSelected(this)'>");
write("<font id=cellText Victor='Liming Weng'> </font>");
write("</td>")
}
write("</tr>");
}
}
}

function fUpdateCal(iYear, iMonth) {
myMonth = fBuildCal(iYear, iMonth);
var i = 0;
for (w = 0; w < 6; w++)
for (d = 0; d < 7; d++)
with (cellText[(7*w)+d]) {
Victor = i++;
if (myMonth[w+1][d]<0) {
color = gcGray;
innerText = -myMonth[w+1][d];
}else{
color = ((d==0)||(d==6))?"red":"black";
innerText = myMonth[w+1][d];
}
}
}

function fSetYearMon(iYear, iMon){
tbSelMonth.options[iMon-1].selected = true;
for (i = 0; i < tbSelYear.length; i++)
if (tbSelYear.options[i].value == iYear)
tbSelYear.options[i].selected = true;
fUpdateCal(iYear, iMon);
}

function fPrevMonth(){
var iMon = tbSelMonth.value;
var iYear = tbSelYear.value;

if (--iMon<1) {
iMon = 12;
iYear--;
}

fSetYearMon(iYear, iMon);
}

function fNextMonth(){
var iMon = tbSelMonth.value;
var iYear = tbSelYear.value;

if (++iMon>12) {
iMon = 1;
iYear++;
}

fSetYearMon(iYear, iMon);
}

function fGetXY(aTag){
var oTmp = aTag;
var pt = new Point(0,0);
do {
pt.x += oTmp.offsetLeft;
pt.y += oTmp.offsetTop;
oTmp = oTmp.offsetParent;
} while(oTmp.tagName!="BODY");
return pt;
}

var gMonths = new Array("Ene","Feb","Mar","Abr","May","Jun","Jul","A go","Sep","Oct","Nov","Dic");

with (document) {
write("<table id='popTable' border='0' bgcolor='#6699cc'>");
write("<TR>");
write("<td valign='middle' align='center'><input type='button' name='PrevMonth' value='<' style='height:20;width:20;FONT:16 Fixedsys' onClick='fPrevMonth()'>");
write("&nbsp;<select name='tbSelMonth' onChange='fUpdateCal(tbSelYear.value, tbSelMonth.value)' Victor='Won'>");
for (i=0; i<12; i++)
write("<option value='"+(i+1)+"'>"+gMonths[i]+"</option>");
write("</SELECT>");
write("&nbsp;<SELECT name='tbSelYear' onChange='fUpdateCal(tbSelYear.value, tbSelMonth.value)' Victor='Won'>");
for(i=2004;i<2016;i++)
write("<OPTION value='"+i+"'>"+i+"</OPTION>");
write("</SELECT>");
write("&nbsp;<input type='button' name='PrevMonth' value='>' style='height:20;width:20;FONT:16 Fixedsys' onclick='fNextMonth()'>");
write("</td>");
write("</TR><TR>");
write("<td align='center'>");
write("<DIV style='background-color:teal;'><table width='100%' border='0' cellpadding='2'>");
fDrawCal(giYear, giMonth, 19, 12);
write("</table></DIV>");
write("</td>");
write("</TR><TR><TD align='center'>");
//ACOMODO DE FECHA POR EL DIA ACTUAL
write("<font style='cursor:hand;font:12 Fixedsys' onclick='fSetDate(giYear,giMonth,giDay)' onMouseOver='this.style.color=gcToggle' onMouseOut='this.style.color=0'>Hoy:&nbsp;&nbsp;"+ giDay+"&nbsp;"+gMonths[giMonth-1]+"&nbsp;"+giYear+"</font>");//
write("</TD></TR>");write("</TD></TR>");
write("</TABLE>");
}
</SCRIPT>
</BODY></HTML>

Ojala y me puedan ayudar porque he estado batallando con este calendario por un buen de tiempo... se los agradezco de antemano...
salu2!!!!
__________________
Dejame conocer todo lo que sabes...
  #2 (permalink)  
Antiguo 21/06/2004, 12:52
 
Fecha de Ingreso: abril-2004
Ubicación: Aguascalientes
Mensajes: 65
Antigüedad: 20 años
Puntos: 0
chavos moderadores ustedes me podrìan ayudar, yo se que el còdigo esta medio raro, pero espero que me puedan ayudar...gracias.....
__________________
Dejame conocer todo lo que sabes...
  #3 (permalink)  
Antiguo 21/06/2004, 15:18
Avatar de Carlitos
Usuario no validado
 
Fecha de Ingreso: mayo-2001
Ubicación: Zaragoza
Mensajes: 1.304
Antigüedad: 22 años, 11 meses
Puntos: 25
Hola

No soy moderador pero te digo como hacerlo.

localiza esta línea: (está de las primeras)
Código:
var giDay = gdCurDate.getDate()
y añade debajo está otra:
Código:
if (giDay < 10) giDay = "0"+giDay
Esto es para el día. El mes sale en palabra, no? (Ene Feb Mar ...)

Por cierto, el calendario no funciona bien. o soy yo?
  #4 (permalink)  
Antiguo 21/06/2004, 15:47
 
Fecha de Ingreso: abril-2004
Ubicación: Aguascalientes
Mensajes: 65
Antigüedad: 20 años
Puntos: 0
Hola, Carlos:

Gracias por tu ayuda, mira ya le añadì esa linea que me dijiste al dìa, pero no me añade el 0 me sigue mostrando este formato (2004-1-1), el mes tambièn lo muestra en nùmero no en palabra y el calendario si me funciona bien, a no ser por ese pequeño detalle que le falta que aparezca el 0 antes del dìa y/ o mes, lo que pasa es que como estoy sustrayendo el mes y el dìa, necesito que las posiciones del mes y dia sean las mismas en todos los casos, aunque el mes sea 1 o 10...
__________________
Dejame conocer todo lo que sabes...
  #5 (permalink)  
Antiguo 22/06/2004, 07:45
Avatar de Carlitos
Usuario no validado
 
Fecha de Ingreso: mayo-2001
Ubicación: Zaragoza
Mensajes: 1.304
Antigüedad: 22 años, 11 meses
Puntos: 25
A ver. Esto es lo que me sale a mi. (en la fecha de hoy, el 0 delante del 1 y el mes en letra. Además no pinta bien el calendario)


Y si paso de mes, me sale esto. (solo completa la primera semana)


No te sale esto a ti?
  #6 (permalink)  
Antiguo 22/06/2004, 09:36
 
Fecha de Ingreso: abril-2004
Ubicación: Aguascalientes
Mensajes: 65
Antigüedad: 20 años
Puntos: 0
Mira te voy a mandar el còdigo que tengo porque a mi si me sale bien, lo primero que hago es desplegar el calendario y seleccionar una fecha de èl y la fecha seleccionada la pongo en un edit, luego la guardo en una tabla que esta en una BD de MySql, debes de tener un script en html o en php para que te muestre el calendario y en la misma ruta donde guardas tu archivo, debes de tener el archivo que pinta el calendario el que te mande ("popcjs.html" )...

mira este es el còdigo :

<html>
<head>
<title>Untitled</title>
</head>
<body bgcolor="#336699">
<DIV id=popCal
style="BORDER-RIGHT: 2px ridge; BORDER-TOP: 2px ridge; Z-INDEX: 100; VISIBILITY: hidden; BORDER-LEFT: 2px ridge; WIDTH: 10px; BORDER-BOTTOM: 2px ridge; POSITION: absolute"
onclick=event.cancelBubble=true><IFRAME name=popFrame
src="popcjs.html"
frameBorder=0 width=183 scrolling=no height=188></IFRAME></DIV>
<SCRIPT event=onclick()
for=document>popCal.style.visibility = "hidden";
</SCRIPT>
<style>
p{color:#000066;font-family:Verdana;Font-size:10px}
</style>
<link rel=stylesheet type= "text/css" href="estilos/estilo1.css">
<head>

<body bgcolor="336699">
<table border="0" align="center">
<form name="form1" method="POST" action="calendario_escolar2.php"> <!--onsubmit="validar(this)">-->

<tr><td align="CENTER">
<B>CICLO-ESCOLAR Dìa/Mes/Año</B><BR>

<tr><td align="right">
<b>INICIAL</b><INPUT style="TEXT-ALIGN: center" readOnly name="Cmbfecha_inicial" size="10"><INPUT onclick="popFrame.fPopCalendar(Cmbfecha_inicial,Cm bfecha_inicial,popCal);return false" type=button value=V >
<b>FINAL</b><INPUT style="TEXT-ALIGN: center" readOnly name="Cmbfecha_final" size="10"><INPUT onclick="popFrame.fPopCalendar(Cmbfecha_final,Cmbf echa_final,popCal);return false" type=button value=V ><br><br>
</td></tr>

<tr><td align="right">
<INPUT TYPE="SUBMIT" VALUE="Ver Meses del Ciclo_Escolar" name='Btnver'> </TD></TR>

</table>
</form>

</body>

</html>

y luego guardas este còdigo en la misma ruta que el "popcjs.html"
__________________
Dejame conocer todo lo que sabes...
  #7 (permalink)  
Antiguo 22/06/2004, 10:21
 
Fecha de Ingreso: abril-2004
Ubicación: Aguascalientes
Mensajes: 65
Antigüedad: 20 años
Puntos: 0
Pregunta

Cita:
Iniciado por Carlitos
A ver. Esto es lo que me sale a mi. (en la fecha de hoy, el 0 delante del 1 y el mes en letra. Además no pinta bien el calendario)


Y si paso de mes, me sale esto. (solo completa la primera semana)


No te sale esto a ti?


A mi si me sale bien el calendario, porque le puse un edit para que ponga la fecha ahì, mira ahi te va el còdigo:

<html>
<head>
<title>Untitled</title>
</head>
<body bgcolor="#336699">
<DIV id=popCal
style="BORDER-RIGHT: 2px ridge; BORDER-TOP: 2px ridge; Z-INDEX: 100; VISIBILITY: hidden; BORDER-LEFT: 2px ridge; WIDTH: 10px; BORDER-BOTTOM: 2px ridge; POSITION: absolute"
onclick=event.cancelBubble=true><IFRAME name=popFrame
src="popcjs.html"
frameBorder=0 width=183 scrolling=no height=188></IFRAME></DIV>
<SCRIPT event=onclick()
for=document>popCal.style.visibility = "hidden";
</SCRIPT>
<style>
p{color:#000066;font-family:Verdana;Font-size:10px}
</style>
<link rel=stylesheet type= "text/css" href="estilos/estilo1.css">
<head>

<body bgcolor="336699">
<table border="0" align="center">
<form name="form1" method="POST" action="calendario_escolar2.php"> <!--onsubmit="validar(this)">-->

<tr><td align="CENTER">
<B>CICLO-ESCOLAR Dìa/Mes/Año</B><BR>

<tr><td align="right">
<b>INICIAL</b><INPUT style="TEXT-ALIGN: center" readOnly name="Cmbfecha_inicial" size="10"><INPUT onclick="popFrame.fPopCalendar(Cmbfecha_inicial,Cm bfecha_inicial,popCal);return false" type=button value=V >
<b>FINAL</b><INPUT style="TEXT-ALIGN: center" readOnly name="Cmbfecha_final" size="10"><INPUT onclick="popFrame.fPopCalendar(Cmbfecha_final,Cmbf echa_final,popCal);return false" type=button value=V ><br><br>
</td></tr>

<tr><td align="right">
<INPUT TYPE="SUBMIT" VALUE="Ver Meses del Ciclo_Escolar" name='Btnver'> </TD></TR>

</table>
</form>

</body>

</html>

El archivo que te mande "popcjs.html" es el que pinta el calendario y este archivo se llama captura_ciclo-escolar es el que te va a mostrar los edits con los calendarios desplegables para que el usuario pueda capturar la fecha sin necesidad de escribirla y todo esto lo guardo en una Base de Datos, te digo que el calendario si funciona, pero lo que yo quiero es agregarle el 0 al dìa y al mes y no se como hacerle , ya le intente como tu me dijiste, pero no me sale, que màs me recomiendas que haga para poder solucionar mi problema, es que mira que si influye mucho porque como estoy sustrayendo el mes pues si le pongo 10 me da otro resultado del que yo necesito, ojala me haya explicado, te agradezco una opiniòn al respecto...
Bye!!!
__________________
Dejame conocer todo lo que sabes...
  #8 (permalink)  
Antiguo 23/06/2004, 10:17
 
Fecha de Ingreso: abril-2004
Ubicación: Aguascalientes
Mensajes: 65
Antigüedad: 20 años
Puntos: 0
Hola Carlos:

que crees no he encontrado la soluciòn de agregarle el 0 al mes y al dìa... como crees que lo pueda resolver?...
Gracias por tu atenciòn....
__________________
Dejame conocer todo lo que sabes...
  #9 (permalink)  
Antiguo 23/06/2004, 10:20
 
Fecha de Ingreso: abril-2004
Ubicación: Aguascalientes
Mensajes: 65
Antigüedad: 20 años
Puntos: 0
Ah y el archivo que te mande lo tienes que correr desde el explorer y tener php porque si no no te muestra el calendario...
__________________
Dejame conocer todo lo que sabes...
  #10 (permalink)  
Antiguo 19/02/2010, 16:01
 
Fecha de Ingreso: febrero-2010
Mensajes: 1
Antigüedad: 14 años, 2 meses
Puntos: 0
Respuesta: Agregar Un 0 Al Mes 1 De Un Calendario?

Hola cambia la funcion
function fSetDate(iYear, iMonth, iDay){
gdCtrl.value = iYear+"-"+iMonth+"-"+iDay; //Here, you could modify the locale as you need !!!!
VicPopCal.style.visibility = "hidden";
}


por
function fSetDate(iYear, iMonth, iDay){
if (iDay < 10) iDay = "0"+iDay;
if (iMonth < 10) iMonth = "0"+iMonth;
gdCtrl.value = iDay+"/"+iMonth+"/"+iYear; //Here, you could modify the locale as you need !!!!
VicPopCal.style.visibility = "hidden";
}
// Escribe en tu input tipo text el formato de fecha 01/02/2010, si deseas cambiarlo lo puedes hacer intercambiando las variables iDay, iMonth y Year..
//Se que es un poco tarde, para la persona que pregunto, pero espero le sirva a alguien mas....
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.
Tema Cerrado




La zona horaria es GMT -6. Ahora son las 17:27.