?
Solved

Concatenating Date Values

Posted on 2005-03-14
5
Medium Priority
?
263 Views
Last Modified: 2010-08-05
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>
0
Comment
Question by:christie_holtz
  • 2
  • 2
5 Comments
 
LVL 35

Accepted Solution

by:
YZlat earned 2000 total points
ID: 13537154
try

start_dt=startmont + startday + startyear

or

start_dt=startmont & startday & startyear
0
 

Author Comment

by:christie_holtz
ID: 13537196
what about the '/' i'll need since it is a date?
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13537514
cfset start_dt = #CreateDateTime(startyear, startmonth, starday, 0,0,0)#
0
 
LVL 35

Expert Comment

by:YZlat
ID: 13537867
start_dt=startmont + "/" + startday +"/" +  startyear

or

start_dt=startmont & "/" &  startday & "/" & startyear
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13538578
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)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month8 days, 11 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question