Alpha Video Training
Results 1 to 6 of 6

Thread: Simple date calculation add X days to date to restrict date picker

  1. #1
    Member
    Real Name
    Darren Parsons
    Join Date
    Aug 2015
    Posts
    189

    Default Simple date calculation add X days to date to restrict date picker

    Good afternoon,

    I am sorry for asking this question, it seems like it should be a very simple thing. Dates in Javascript. I have a date picker with a start date. I want the end date to be no more than a week later than the date picked in the date picker.

    So I need a function for the date picker that will read the value in the start date then restrict the end date.

    I have looked through these boards, online help and can't seem to nail it. Would someone kindly point me in the right direction?

  2. #2
    Volunteer Moderator Steve Workings's Avatar
    Real Name
    Steve Workings
    Join Date
    Apr 2000
    Location
    The Dreaded Chair
    Posts
    5,629

    Default Re: Simple date calculation add X days to date to restrict date picker

    -Steve


  3. #3
    Banned
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,819

    Default Re: Simple date calculation add X days to date to restrict date picker

    Code:
    var sDate = {dialog.Object}.getDateValue('dateStart');
    var eDate = {dialog.Object}.getDateValue('dateEnd');
    sDate.setDate(sDate.getDate() + 7);
    if(eDate > sDate){
    	alert('sorry... cannot do that');
    }

  4. #4
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: Simple date calculation add X days to date to restrict date picker

    you can also do this way, (based on the code from a year ago)
    Code:
    function getDate() {
    /*
    This function will compute the high date shown in the Date Picker.
    The function must return a date value (using the Date format that the Date Picker is set to use).
    Example:
    return '08/15/2024';
    */
    var j1 = {dialog.Object}.getValue('YOUR_DATE_CONTROL');
    j1 = new Date(j1);
    var j2 = new Date(j1.getTime() + (7 * 86400000));
    return j2.toFormat('MM/dd/yyyy');
    }
    (original code, here,did not account for past or future dates)
    this corrects for any date in the past or future
    Last edited by GGandhi; 10-07-2017 at 06:01 AM.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  5. #5
    Banned
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,819

    Default Re: Simple date calculation add X days to date to restrict date picker

    I just recalled that there is an Alpha client-side method named ".addTime()"... very handy. So... if you're using a build of Alpha that contains current methods... you might as well use them.

    .getDateValue() and .addTime() make working with dates and times palatable... instead of tedious.

    Code:
    var sDate = {dialog.Object}.getDateValue('dateStart');
    var eDate = {dialog.Object}.getDateValue('dateEnd');
    var testStartDate = sDate.addTime("day",7);
    if(eDate > testStartDate){
    	alert('sorry... cannot do that');
    }

  6. #6
    "Certified" Alphaholic
    Real Name
    Lee Vasic
    Join Date
    May 2010
    Location
    Salt Lake City
    Posts
    1,223

    Default Re: Simple date calculation add X days to date to restrict date picker

    David, I need your memory. I don't even remember seeing those functions. Thanks for your code. I will change all of my tedious code... This will really help.

Similar Threads

  1. Replies: 1
    Last Post: 09-22-2016, 02:24 AM
  2. How to combine a date and time from two fields into one (date picker)
    By PhotoHog in forum Mobile & Browser Applications
    Replies: 3
    Last Post: 07-14-2016, 02:55 PM
  3. Date picker restrict dates
    By Terrymorgan in forum Mobile & Browser Applications
    Replies: 3
    Last Post: 01-25-2016, 06:15 AM
  4. Disabling Week Days in the date picker
    By WindForce in forum Application Server Version 11 - Web/Browser Applications
    Replies: 2
    Last Post: 03-06-2012, 05:22 AM
  5. Difficulties Using Date Picker to Insert Date Values
    By Noel in forum Application Server Version 8
    Replies: 3
    Last Post: 01-12-2008, 07:51 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •