function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
How do you take a date value and determine if it falls within two other date values?
Ran a quick test using the following in anonymous block. Seemed okay.
string year = '2008';
string month = '10';
string day = '5'; string day2 = '6';
string hour = '12';
string minute = '20';
string second = '20';
string stringDate = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
string stringDate2 = year + '-' + month + '-' + day2 + ' ' + hour + ':' + minute + ':' + second;
Date myDate = date.valueOf(stringDate);
Date myDate2 = date.valueOf(stringDate2);
System.debug(''+(myDate>myDate2));
System.debug(''+(myDate<myDate2));
System.debug(''+(myDate==myDate2));
hence
if(date1<testdate&& testdate<date2)
you could try
integer dates = firstdate.daysbetween(seconddate)
integer datetotest= thirddate.daysbetween(seconddate)
if (datetotest>dates){
//you have a date between two dates
}
I'm not 100% sure but try using <,>,==, with your dates. It's definitely supported for datetimes. Create some dates in an anonymous block and see whether they respond as you would expect.
Thanks for the response. I did the following (borrowing heavily from your example) and it works like a charm
Date myDate = date.valueOf('2004-6-6'); Date startDate = date.valueOf('2000-5-5'); Date endDate = date.valueOf('2004-6-6'); System.Debug(myDate >= startDate && myDate <= endDate);
Ran a quick test using the following in anonymous block. Seemed okay.
string year = '2008';
string month = '10';
string day = '5'; string day2 = '6';
string hour = '12';
string minute = '20';
string second = '20';
string stringDate = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
string stringDate2 = year + '-' + month + '-' + day2 + ' ' + hour + ':' + minute + ':' + second;
Date myDate = date.valueOf(stringDate);
Date myDate2 = date.valueOf(stringDate2);
System.debug(''+(myDate>myDate2));
System.debug(''+(myDate<myDate2));
System.debug(''+(myDate==myDate2));
hence
if(date1<testdate&& testdate<date2)
All Answers
you could try
integer dates = firstdate.daysbetween(seconddate)
integer datetotest= thirddate.daysbetween(seconddate)
if (datetotest>dates){
//you have a date between two dates
}
I'm not 100% sure but try using <,>,==, with your dates. It's definitely supported for datetimes. Create some dates in an anonymous block and see whether they respond as you would expect.
Ran a quick test using the following in anonymous block. Seemed okay.
string year = '2008';
string month = '10';
string day = '5'; string day2 = '6';
string hour = '12';
string minute = '20';
string second = '20';
string stringDate = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
string stringDate2 = year + '-' + month + '-' + day2 + ' ' + hour + ':' + minute + ':' + second;
Date myDate = date.valueOf(stringDate);
Date myDate2 = date.valueOf(stringDate2);
System.debug(''+(myDate>myDate2));
System.debug(''+(myDate<myDate2));
System.debug(''+(myDate==myDate2));
hence
if(date1<testdate&& testdate<date2)
Thanks for the response. I did the following (borrowing heavily from your example) and it works like a charm