Date range should not exceed 90 days ..

5 posts, 0 answers
  1. chandrasekaran
    chandrasekaran avatar
    14 posts
    Member since:
    Jan 2009

    Posted 09 Feb 2009 Link to this post

    HI,
    i have two rad datepicker  control. i want to valiate that User-entered date range should not exceed 90 days from the startdate using javascript. any one help me.
    thx
    chandrasekarank
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 10 Feb 2009 Link to this post

    Hi,

    One suggestion is to set the MaxDate property of the second RadDatePicker according to the date selected using first RadDatePicker. Set the MaxDate 90 days ahead of the first RadDatePicker's selected date, so that the rest of the days will not be selectable. Try the following Javascript:

    JavaScript:
    <script type="text/javascript">  
    function  validate()  
    {  
        var datepicker1 = $find("<%= RadDatePicker1.ClientID %>");  
        var date= datepicker1.get_selectedDate();  // Get the selected date from first datepicker  
        var datepicker2 = $find("<%= RadDatePicker2.ClientID %>");     
        datepicker2.set_minDate(date);  // Sets the MisDate  
        date.setDate(date.getDate() + 90);     //Adds 90 days  
        datepicker2.set_maxDate(date);  // Sets the MaxDate  
    }  
    </script> 

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. chandrasekaran
    chandrasekaran avatar
    14 posts
    Member since:
    Jan 2009

    Posted 11 Feb 2009 Link to this post

    Hi,
    Thank u for ur idea..based on that i have fullfilled  my requrirement and i have added the coding also..
    thx,
    chandrasekaranK

     

    function Validate90Days1()

     

    {

     

     

    var txtFromDate = document.getElementById('<%=txtFromDate.ClientID %>');

     

     

     

    var txtToDate = document.getElementById('<%=txtToDate.ClientID %>');

     

     

     

     

    var getyy = txtFromDate.value.substring(0, 4);

     

     

     

    var getmm = txtFromDate.value.substring(5, 7);

     

     

     

    var getdd = txtFromDate.value.substring(8, 10);

     

     

     

    var mydate = getmm + "/" + getdd + "/" + getyy;

     

     

     

     

    var x = new Date(mydate);

     

     

     

    var y= x.getFullYear();

     

     

     

    var m= x.getMonth()+1; // added +1 because javascript counts month from 0

     

     

     

    var d= x.getDate()+ 90;

     

     

    mydate = m +

     

    "/" + d + "/" + y;

     

     

     

    var objdateFrom = new Date(mydate);

     

     

     

     

     

    var getyyTO = txtToDate.value.substring(0, 4);

     

     

     

    var getmmTO = txtToDate.value.substring(5, 7);

     

     

     

    var getddTO = txtToDate.value.substring(8, 10);

     

     

     

    var mydateTO = getmmTO + "/" + getddTO + "/" + getyyTO;

     

     

     

     

    var objToDate = new Date(mydateTO);

     

     

     

     

     

    if (objdateFrom < objToDate)

     

    {

    alert(

     

    "Date range should not exceed 90 days");

     

     

     

    return false;

     

    }

     

     

    }



     

     

     

    function Validate90Days()

     

    {

     

     

    var fromdateControl = document.getElementById('<%=txtFromDate.ClientID %>');

     

     

     

    var todateControl = document.getElementById('<%=txtToDate.ClientID %>');

     

     

     

    var fromDateValue = fromdateControl.value;

     

     

     

    var dayPartFromDate = parseInt(fromDateValue.substring(8, 10), 10);

     

     

     

    var monPartFromDate = parseInt(fromDateValue.substring(5, 8), 10);

     

     

     

    var yearPartFromDate = parseInt(fromDateValue.substring(0, 5), 10);

     

     

     

    var dtFrom = new Date(yearPartFromDate, monPartFromDate - 1, dayPartFromDate);

     

     

     

    var toDateValue = todateControl.value;

     

     

     

    var dayPartToDate = parseInt(toDateValue.substring(8, 10), 10);

     

     

     

    var monPartToDate = parseInt(toDateValue.substring(5, 8), 10);

     

     

     

    var yearPartToDate = parseInt(toDateValue.substring(0, 5), 10);

     

     

     

    var dtTo = new Date(yearPartToDate, monPartToDate - 1, dayPartToDate);

     

     

     

    if (fromDateValue != "")

     

    {

     

     

    var one_day = 1000 * 60 * 60 * 24;

     

     

     

    var days = (dtTo.getTime() - dtFrom.getTime()) / (one_day);

     

     

     

    if (days > 90) {

     

    alert(

     

    'To Date should not be greater than 90 days from the From Date');

     

     

     

    return false;

     

    }

    }

    }

     

     

  5. P
    P avatar
    1 posts
    Member since:
    Oct 2010

    Posted 06 Oct 2010 Link to this post

    Thanks you very much for sharing the solution.
  6. Nital
    Nital avatar
    1 posts
    Member since:
    Mar 2013

    Posted 26 Mar 2013 Link to this post

    The simplest example to check range of date should be between 90 days as below.


    var today = new Date();
    //alert(today);

    var future_date = new Date('2012/01/26 13:03:35 GMT-0400');
    //alert(future_date);

    var difference = today.getTime() - future_date.getTime();
    var thirty_days = 3600 * 24 * 90 * 1000;
    //alert(difference);
    if(difference > thirty_days)
    {
        alert(false);
    }
    else
    {
        alert(true);
    }

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017