?
Solved

Concatenating Date Values

Posted on 2005-03-14
5
Medium Priority
?
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Suggested Courses

764 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