christie_holtz
asked on
Concatenating Date Values
Hello! I'm using the following java script to check the validity of dates that are entered. I need to concatenate the validated fields: startday, startmonth, startyear, etc. in the start_dt. The format should be a date startmonth/startday/starty ear. I tried just using cfset start_dt=#startmont# + #startday# + #startyear#, but that gives me an error. I'll give 500 points and I definite A for answer.
<cfform name="Insertform" method="post" action="./report_vacation. cfm">
<script language="JavaScript"><!--
function padout(number) { return (number < 10) ? '0' + number : number; }
function y2k(number) { return (number < 1000) ? number + 1900 : number; }
function validate(what) {
var startday = what.startday.options[what .startday. selectedIn dex].value ;
var startmonth = what.startmonth.options[wh at.startmo nth.select edIndex].v alue;
var startyear = what.startyear.options[wha t.startyea r.selected Index].tex t;
var endday = what.endday.options[what.e ndday.sele ctedIndex] .value;
var endmonth = what.endmonth.options[what .endmonth. selectedIn dex].value ;
var endyear = what.endyear.options[what. endyear.se lectedInde x].text;
unvalidstartdate = startday + '/' + startmonth + '/' + startyear;
unvalidenddate = endday + '/' + endmonth + '/' + endyear;
var startdate = new Date(startyear-0,startmont h-1,startd ay-0);
var enddate = new Date(endyear-0,endmonth-1, endday-0);
var validstartdate = padout(startdate.getDate() ) + '/' + padout(startdate.getMonth( )+1) + '/' + y2k(startdate.getYear())
var validenddate = padout(enddate.getDate()) + '/' + padout(enddate.getMonth()+ 1) + '/' + y2k(enddate.getYear())
if (unvalidstartdate != validstartdate) {
alert('Start Date: ' + what.startday.options[what .startday. selectedIn dex].text +
' ' + what.startmonth.options[wh at.startmo nth.select edIndex].t ext +
' ' + what.startyear.options[wha t.startyea r.selected Index].tex t + ' is invalid');
return false;
}
if (unvalidenddate != validenddate) {
alert('End Date: ' + what.endday.options[what.e ndday.sele ctedIndex] .text +
' ' + what.endmonth.options[what .endmonth. selectedIn dex].text +
' ' + what.endyear.options[what. endyear.se lectedInde x].text + ' is invalid');
return false;
}
starttime = Date.UTC(y2k(startdate.get Year()),st artdate.ge tMonth(),s tartdate.g etDate(),0 ,0,0);
endtime = Date.UTC(y2k(enddate.getYe ar()),endd ate.getMon th(),endda te.getDate (),0,0,0);
if (starttime < endtime) {
// valid
}
else {
alert('Start Date is not less than End Date');
return false
}
currentdate = new Date();
currenttime = Date.UTC(y2k(currentdate.g etYear()), currentdat e.getMonth (),current date.getDa te(),0,0,0 );
if (starttime > currenttime) {
// valid
}
else {
alert('Start Date cannot be less then todays date');
return false;
}
what.startdate.value = validstartdate;
what.enddate.value = validenddate;
return true;
}
//--></script>
<cfform name="Insertform" method="post" action="./report_vacation.
<script language="JavaScript"><!--
function padout(number) { return (number < 10) ? '0' + number : number; }
function y2k(number) { return (number < 1000) ? number + 1900 : number; }
function validate(what) {
var startday = what.startday.options[what
var startmonth = what.startmonth.options[wh
var startyear = what.startyear.options[wha
var endday = what.endday.options[what.e
var endmonth = what.endmonth.options[what
var endyear = what.endyear.options[what.
unvalidstartdate = startday + '/' + startmonth + '/' + startyear;
unvalidenddate = endday + '/' + endmonth + '/' + endyear;
var startdate = new Date(startyear-0,startmont
var enddate = new Date(endyear-0,endmonth-1,
var validstartdate = padout(startdate.getDate()
var validenddate = padout(enddate.getDate()) + '/' + padout(enddate.getMonth()+
if (unvalidstartdate != validstartdate) {
alert('Start Date: ' + what.startday.options[what
' ' + what.startmonth.options[wh
' ' + what.startyear.options[wha
return false;
}
if (unvalidenddate != validenddate) {
alert('End Date: ' + what.endday.options[what.e
' ' + what.endmonth.options[what
' ' + what.endyear.options[what.
return false;
}
starttime = Date.UTC(y2k(startdate.get
endtime = Date.UTC(y2k(enddate.getYe
if (starttime < endtime) {
// valid
}
else {
alert('Start Date is not less than End Date');
return false
}
currentdate = new Date();
currenttime = Date.UTC(y2k(currentdate.g
if (starttime > currenttime) {
// valid
}
else {
alert('Start Date cannot be less then todays date');
return false;
}
what.startdate.value = validstartdate;
what.enddate.value = validenddate;
return true;
}
//--></script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
cfset start_dt = #CreateDateTime(startyear, startmonth, starday, 0,0,0)#
start_dt=startmont + "/" + startday +"/" + startyear
or
start_dt=startmont & "/" & startday & "/" & startyear
or
start_dt=startmont & "/" & startday & "/" & startyear
YZlat,
She said>The format should be a date
That would give you a string rather than a date. (Of course she may not care if it is a date or a string, I was just going by her original question)
She said>The format should be a date
That would give you a string rather than a date. (Of course she may not care if it is a date or a string, I was just going by her original question)
ASKER