
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-07-2016 04:42 AM
I have a date field where I want to ensure that the date selected from the date variable is not greater than the current days date. I have the following code for another date field that has to be 5 days out. Not very good with the date thing yet, so 1) should i have something like a (-1) in my dateMS portion of the script. And 2) will it render an error if the customer tries to select a date in the past or should I include some code that has an alert type of box stating something like "Please select a future date"......
var today = new Date();
var dateMS = today.getTime();
dateMS = dateMS + (5*24*60*60*1000);
var newDT = new Date();
newDT.setTime(dateMS);
g_form.setValue('ftr_needed_by',formatDate(newDT,g_user_date_format));
Thank you,
Karen
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2016 12:35 PM
Karen,
Nothing wrong with the code, what happening is that 'getUTCDate() returns the day;
The reason that it did not allow you to select 2nd March is because 2 is lesser than 8 (current day) and conversely 16 (febr) is greater than 8 !!
I will suggest you to try with dateDiff() method to calculate the difference between two date/times given.
let me know if you have more concerns
Kind regards
Do not feel shy to mark correct or helpful answer if it helps or is correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2016 10:10 AM
Karen,
I am glad that your script is works
However, I think that does not cover every cases.
I explain : we are the 8th today. Could you please choose 2nd march 2016 as date on Needed_by_date field ? For this case, the field should be erased >> test successful
Now, could you choose 16th February 2016 as date ? Unless I am wrong, I am afraid this test wont succeed.
Could you please let me know ?
Kind regards,
Za
Do not feel shy to mark correct or helpful answer if it helps or is correct

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2016 11:35 AM
I may not be fully understanding what you are trying to say. I only wanted to prevent someone from selecting a date prior to today's date. I did test it out, and I was not able to select (in your case/example) March 2nd. If I tried to select March 2nd - the form will not allow it, you would receive the error message and you will have to choose a date either today or any date after.
I did go back and selected February 16th and you are correct, it did allow me to select that day. I will go back and check the code again.
I hope I successfully answered your question for the most part.
Thank you,
Karen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2016 12:35 PM
Karen,
Nothing wrong with the code, what happening is that 'getUTCDate() returns the day;
The reason that it did not allow you to select 2nd March is because 2 is lesser than 8 (current day) and conversely 16 (febr) is greater than 8 !!
I will suggest you to try with dateDiff() method to calculate the difference between two date/times given.
let me know if you have more concerns
Kind regards
Do not feel shy to mark correct or helpful answer if it helps or is correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-06-2024 08:54 AM
And what worked for me is the below client script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
// Get today's date, stripping off the time part
var today = new Date();
today.setHours(0, 0, 0, 0);
// Create a date object from the newValue
var selectedDate = new Date(newValue);
selectedDate.setHours(0, 0, 0, 0); // Normalize time for accurate comparison
// Check if the selected date is less than or equal to today's date
if (selectedDate <= today) {
// Show an alert if the selected date is not in the future
alert("Date of desired ongoing to production cannot be in the past or today's date. Please select a future date.");
// Clear the current value of the date field
g_form.setValue('date_of_desired_ongoing_to_production', '');
}
}