Link to home
Start Free TrialLog in
Avatar of christie_holtz
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/startyear.  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.selectedIndex].value;
    var startmonth = what.startmonth.options[what.startmonth.selectedIndex].value;
    var startyear = what.startyear.options[what.startyear.selectedIndex].text;
    var endday = what.endday.options[what.endday.selectedIndex].value;
    var endmonth = what.endmonth.options[what.endmonth.selectedIndex].value;
    var endyear = what.endyear.options[what.endyear.selectedIndex].text;

    unvalidstartdate = startday + '/' + startmonth + '/' + startyear;
    unvalidenddate = endday + '/' + endmonth + '/' + endyear;

    var startdate = new Date(startyear-0,startmonth-1,startday-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.selectedIndex].text +
                         ' ' + what.startmonth.options[what.startmonth.selectedIndex].text +
                         ' ' + what.startyear.options[what.startyear.selectedIndex].text + ' is invalid');
        return false;
    }

    if (unvalidenddate != validenddate) {
        alert('End Date: ' + what.endday.options[what.endday.selectedIndex].text +
                       ' ' + what.endmonth.options[what.endmonth.selectedIndex].text +
                       ' ' + what.endyear.options[what.endyear.selectedIndex].text + ' is invalid');
        return false;
    }

    starttime = Date.UTC(y2k(startdate.getYear()),startdate.getMonth(),startdate.getDate(),0,0,0);
    endtime = Date.UTC(y2k(enddate.getYear()),enddate.getMonth(),enddate.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.getYear()),currentdate.getMonth(),currentdate.getDate(),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>
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of christie_holtz
christie_holtz

ASKER

what about the '/' i'll need since it is a date?
cfset start_dt = #CreateDateTime(startyear, startmonth, starday, 0,0,0)#
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)