...

View Full Version : populating custom dates in Drop down list



gadaschowdary
01-07-2010, 08:58 PM
I have a reservation page where there is a maximum day limit which can be set from 1 thru 5 on config.php

After setting it, from addreservation.php page i will retreive it and based on the value i have to populate those many dates from today's date.

suppose the noofdays is set to 4, the drop down list should populate
like this..
01/07/2010
01/08/2010
01/09/2010
01/10/2010
if it is five it should have
01/07/2010 thru 01/11/2010 like wise....

i am trying this way..

$NoOfDays = $_SESSION[row]['noofdays']; //getting from database
$today = date ('m-d-Y'); //local variable

now how to compare the dates and display dates.
.any help...

angst
01-07-2010, 09:13 PM
this should work:



$date = date("m/d/Y");
$AddDays = 5;
$Count = 0;
while($Count <= $AddDays){
echo date("m/d/Y",strtotime(date("m/d/Y", strtotime($date)) . " + " . $Count . " day")) . "<br />";
$Count++;

}



result:

01/07/2010
01/08/2010
01/09/2010
01/10/2010
01/11/2010
01/12/2010

JAY6390
01-07-2010, 09:13 PM
function get_dates($number) {
$dates = array();
$time = time();
for($i = 0; $i < $number; $i++) {
$dates[] = date('m-d-Y', $time + ($i * 86400));
}
return $dates;
}
$dates = get_dates($NoOfDays);$dates will contain an array of the dates for you

gadaschowdary
01-11-2010, 09:37 PM
thanx guyz

gadaschowdary
01-11-2010, 09:41 PM
it should be the value that is selected by user on pop up calendar to make reservation. So should it be some thing like this
where ResrvDate is the name of that text area. I tried it this way but it displays

01/02/1970......and so on..


$today= $date("m/d/Y");
$AddDays = 5;
$Count = 0;
while($Count <= $AddDays){
echo date("m/d/Y",strtotime(date("m/d/Y", strtotime($date)) . " + " . $Count . " day")) . "<br />";
$Count++;

gadaschowdary
01-11-2010, 09:53 PM
how do i greyout those array of dates in pop up calendar

if the date is 01/12/2010 and the $noofdays = 5

then i should display the dates less than 01/17/2010 i.e, the 5th day from the entered date.

sorry for the insufficient data earlier!!!

This is the code that i am using for pop up calendar


/* --- Swazz Javascript Calendar ---
/* --- v 1.0 3rd November 2006
By Oliver Bryant
http://calendar.swazz.org */

function getObj(objID)
{
if (document.getElementById) {return document.getElementById(objID);}
else if (document.all) {return document.all[objID];}
else if (document.layers) {return document.layers[objID];}
}

var opening = false;

function checkClick(e) {
e?evt=e:evt=event;
CSE=evt.target?evt.target:evt.srcElement;
calCtrl = getObj('fc');
if (calCtrl != null && calCtrl.style.display == '')
{
if (opening) // fixed issue with not opening from button - sriram
opening = false;
else if (!isChild(CSE,getObj('fc')))
getObj('fc').style.display='none';
}
}

function isChild(s,d) {
while(s) {
if (s==d)
return true;
s=s.parentNode;
}
return false;
}

function Left(obj)
{
var curleft = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
curleft += obj.offsetLeft; // fix - sriram
}
else if (obj.x)
curleft += obj.x;
return curleft;
}

function Top(obj)
{
var curtop = 0;
if (obj.offsetParent)
{
while (obj.offsetParent)
{
curtop += obj.offsetTop
obj = obj.offsetParent;
}
curtop += obj.offsetTop; // fix - sriram
}
else if (obj.y)
curtop += obj.y;
return curtop;
}

document.write('<table id="fc" style="z-index:1000;position:absolute;border-collapse:collapse;background:#FFFFFF;border:1px solid #ABABAB;display:none;" cellpadding=2>');
document.write('<tr><td style="cursor:pointer" onclick="csubm()"><img src="css/images/bullet-blue-button-right.png"></td><td colspan=5 id="mns" align="center" style="font:bold 13px Arial"></td><td align="right" style="cursor:pointer" onclick="caddm()"><img src="css/images/bullet-blue-button.png"></td></tr>');
document.write('<tr><td align=center style="background:#ABABAB;font:12px Arial">S</td><td align=center style="background:#ABABAB;font:12px Arial">M</td><td align=center style="background:#ABABAB;font:12px Arial">T</td><td align=center style="background:#ABABAB;font:12px Arial">W</td><td align=center style="background:#ABABAB;font:12px Arial">T</td><td align=center style="background:#ABABAB;font:12px Arial">F</td><td align=center style="background:#ABABAB;font:12px Arial">S</td></tr>');
for(var kk=1;kk<=6;kk++) {
document.write('<tr>');
for(var tt=1;tt<=7;tt++) {
num=7 * (kk-1) - (-tt);
document.write('<td id="v' + num + '" style="width:18px;height:18px">&nbsp;</td>');
}
document.write('</tr>');
}
document.write('</table>');

document.all?document.attachEvent('onclick',checkClick):document.addEventListener('click',checkClick ,false);


// Calendar script
var now = new Date;
var sccm=now.getMonth();
var sccy=now.getFullYear();
var scfd=now.getDate(); // fix - sriram
var ccm=now.getMonth();
var ccy=now.getFullYear();

var updobj;
function lcs(ielem) {
opening = true; // sriram
updobj=ielem;
getObj('fc').style.left=Left(ielem);
getObj('fc').style.top=Top(ielem)+ielem.offsetHeight;
getObj('fc').style.display='';

// First check date is valid
curdt=ielem.value;
if (curdt == '') // fixed issue with empty date - sriram
{
var currentTime = new Date();
var month = currentTime.getMonth()+1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
curdt = month + "/" + day + "/" + year;
}
curdtarr=curdt.split('/');
isdt=true;
for(var k=0;k<curdtarr.length;k++) {
if (isNaN(curdtarr[k]))
isdt=false;
}
if (isdt&(curdtarr.length==3)) {
ccm=curdtarr[0]-1; // fix month index - sriram
ccy=curdtarr[2];
// prepcalendar(curdtarr[0],curdtarr[1]-1,curdtarr[2]);
prepcalendar(curdtarr[1], ccm, curdtarr[2]); // fix seq and month - sriram
}
}

function evtTgt(e)
{
var el;
if(e.target)el=e.target;
else if(e.srcElement)el=e.srcElement;
if(el.nodeType==3)el=el.parentNode; // defeat Safari bug
return el;
}
function EvtObj(e){if(!e)e=window.event;return e;}
function cs_over(e) {
evtTgt(EvtObj(e)).style.background='#FFCC66';
}
function cs_out(e) {
evtTgt(EvtObj(e)).style.background='#C4D3EA';
}
function cs_click(e) {
updobj.value=calvalarr[evtTgt(EvtObj(e)).id.substring(1,evtTgt(EvtObj(e)).id.length)];
getObj('fc').style.display='none';
}

var mn=new Array('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');
var mnn=new Array('31','28','31','30','31','30','31','31','30','31','30','31');
var mnl=new Array('31','29','31','30','31','30','31','31','30','31','30','31');
var calvalarr=new Array(42);

function f_cps(obj) {
obj.style.background='#C4D3EA';
obj.style.font='10px Arial';
obj.style.color='#333333';
obj.style.textAlign='center';
obj.style.textDecoration='none';
obj.style.border='1px solid #6487AE';
obj.style.cursor='pointer';
}

function f_cpps(obj) {
obj.style.background='#C4D3EA';
obj.style.font='10px Arial';
obj.style.color='#ABABAB';
obj.style.textAlign='center';
obj.style.textDecoration='line-through';
obj.style.border='1px solid #6487AE';
obj.style.cursor='default';
}

function f_hds(obj) {
obj.style.background='#FFF799';
obj.style.font='bold 10px Arial';
obj.style.color='#333333';
obj.style.textAlign='center';
obj.style.border='1px solid #6487AE';
obj.style.cursor='pointer';
}

function d2 (i) { if (i<10) return '0' + i; else return i; }

// day selected
function prepcalendar(hd,cm,cy) {
now=new Date();
sd=now.getDate();
td=new Date();
td.setDate(1);
td.setFullYear(cy);
td.setMonth(cm);
cd=td.getDay();
getObj('mns').innerHTML=mn[cm]+ ' ' + cy;
marr=((cy%4)==0)?mnl:mnn;
for(var d=1;d<=42;d++) {
f_cps(getObj('v'+parseInt(d)));
if ((d >= (cd -(-1))) && (d<=cd-(-marr[cm])))
{
dip=false; // ((d-cd < sd)&&(cm==sccm)&&(cy==sccy)); // strike fix - sriram
htd=((hd!='')&&(d-cd==hd));
if (dip)
f_cpps(getObj('v'+parseInt(d)));
else if (htd)
f_hds(getObj('v'+parseInt(d)));
else
f_cps(getObj('v'+parseInt(d)));

getObj('v'+parseInt(d)).onmouseover=(dip)?null:cs_over;
getObj('v'+parseInt(d)).onmouseout=(dip)?null:cs_out;
getObj('v'+parseInt(d)).onclick=(dip)?null:cs_click;

getObj('v'+parseInt(d)).innerHTML=d-cd;
// calvalarr[d]=''+(d-cd)+'/'+(cm-(-1))+'/'+cy;
calvalarr[d]= '' + d2((cm-(-1))) + '/' + d2((d-cd)) + '/' + cy; // format fix - sriram
}
else {
getObj('v'+d).innerHTML='&nbsp;';
getObj('v'+parseInt(d)).onmouseover=null;
getObj('v'+parseInt(d)).onmouseout=null;
getObj('v'+parseInt(d)).style.cursor='default';
}
}
}

prepcalendar('',ccm,ccy);
//getObj('fc'+cc).style.visibility='hidden';

function caddm() {
marr=((ccy%4)==0)?mnl:mnn;

ccm+=1;
if (ccm>=12) {
ccm=0;
ccy++;
}
cdayf();
prepcalendar('',ccm,ccy);
}

function csubm() {
marr=((ccy%4)==0)?mnl:mnn;

ccm-=1;
if (ccm<0) {
ccm=11;
ccy--;
}
cdayf();
prepcalendar('',ccm,ccy);
}

function cdayf() {
return; // ignore the check -
/*
if ((ccy>sccy)|((ccy==sccy)&&(ccm>=sccm)))
return;
else {
ccy=sccy;
ccm=sccm;
cfd=scfd;
} */
}

/* - added following utility function */
function showandgetdate(ctrlID) {
ctrl = document.getElementById(ctrlID);
// ctrl.select();
lcs(ctrl);
}

// following 2 functions borrowed from firetree.net
function findPosX(obj)
{
var curleft = 0;
if(obj.offsetParent)
while(1)
{
curleft += obj.offsetLeft;
if(!obj.offsetParent)
break;
obj = obj.offsetParent;
}
else if(obj.x)
curleft += obj.x;
return curleft;
}

function findPosY(obj)
{
var curtop = 0;
if(obj.offsetParent)
while(1)
{
curtop += obj.offsetTop;
if(!obj.offsetParent)
break;
obj = obj.offsetParent;
}
else if(obj.y)
curtop += obj.y;
return curtop;
}

krishk25
02-17-2012, 10:48 AM
this should work:



$date = date("m/d/Y");
$AddDays = 5;
$Count = 0;
while($Count <= $AddDays){
echo date("m/d/Y",strtotime(date("m/d/Y", strtotime($date)) . " + " . $Count . " day")) . "<br />";
$Count++;

}



result:

01/07/2010
01/08/2010
01/09/2010
01/10/2010
01/11/2010
01/12/2010

This is fantastic... can we ignore saturdays and sundays using this code??



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum