I'm looking for a way to validate two input datefields in my form.
I have a start date and end date
and conditions to check are
1.start date should not be greater than end date
2.end date should not be less than start date.
I'm trying to create a directive, if there is already a solution, can you please share.
Related
I have form where a user puts in a date but I want to stop the user from inputting a date which is more than the date on the main form if the date is mentioned and the date shoud also be less than the date already on the same form which is the Date From field.
I came up with this valdidation criteria
>=[DateFrom] And IIf([Forms]![FrmPatientInfo]![EndOfTreatment] Is Null,<=Date(),<=[Forms]![FrmPatientInfo]![EndOfTreatment])
It is not letting me put any dates in the field.
Please tell me what I am doing wrong here.
Try with:
>=[DateFrom] And <=Nz([Forms]![FrmPatientInfo]![EndOfTreatment],Date())
or simply:
>=[DateFrom] And <=Nz([EndOfTreatment],Date())
I have 2 main dates : MainFrom and MainTo Depending on these , I have set validations for my work experience date validations in angularjs(I know, it is old but the proejct was written in this version). I can add from and to experience dates.Validation needed:
Main From date > Main To date
other Experince dates should be between these dates.
Other work experience to date should be greater than from date.
I have written lot of conditions to check these.
Could someone suggest less lines of code?
to go with the trend these day try moment in you angularjs app,
first include moment js in your project, the lib will help you in all validations and checks related to dates.
for eg in your cases validation check will something like this:
Main From date > Main To date :
if(moment(Main From date).isAfter(Main To date))
other Experince dates should be between these dates. :
loop on every date
if(moment(other Experince dates).range(startDate, endDate);)
Other work experience to date should be greater than from date.
if(moment(to date).isAfter(Main from date))
Using angularjs, dynamodb as DB here.
I have a form where user saves some data. I save my "CreateOn" date in my dynamo db as:
DateTime.UtcNow.ToString("o");
//This saves date in DB as:2018-08-21T12:58:08.7823906Z
Storing like this because dynamo db requires dates (string) to stored in ISO8601 format if you want to use between operator to search for date range.
Now I have a search filters on my page which is basically an angular calendar. When the user selects the date in the calendar( start and end date) I want to get the data back based on the selected date. Here I am using moment to pass the calendar selected date to my api call as:
moment(createdOn).toISOString()
Eg: If they select the Today's date in the calendar I pass the selected date
(Tue Aug 21 2018 00:00:00 GMT-0400 (Eastern Daylight Time)) to the above function
The result of passing this date to moment(createdOn).toISOString() is
2018-08-21T04:00:00.000Z
The search condition at dynamo db is:
conditions.Add(new ScanCondition("CreatedOn", ScanOperator.Between, startDate, endDate ));
If the user selects from the calendar the start date as "08-20-2018" (2018-08-20T04:00:00.000Z) and the end date is "08-21-2018"(2018-08-21T04:00:00.000Z), the code all the data created b/w these 2 dates.
Now the issue is if they select same start and end date then the code does not returns any data, I believe because the start and end date is "2018-08-21T04:00:00.000Z" and the time part of this is all 0000 etc.
My question is how can I convert the date from my calendar ie my end date to correctly reflect the the end time which they select. I havent used ISO8601 format before so not sure how can I do so.
Thanks
You don't need moment for this. You can zero out the time using a Date in the following way.
const date = new Date('2018-08-21T12:58:08.7823906Z')
date.setUTCHours(0)
date.setUTCMinutes(0)
date.setUTCSeconds(0)
date.setUTCMilliseconds(0)
Then you can simply use toISOString() to format the date.
date.toISOString()
// returns '2018-08-21T00:00:00.000Z'
If you don't want to zero out the time, and instead want to set some specific time, you can use a similar approach, just substitute the 0 with whatever time you want.
Some other things to note: DynamoDB doesn't require any specific formatting for dates. DynamoDB simply does a string or number comparison depending on what the field is defined as. You could store your dates in DynamoDB as integers or another string format if you feel that would be easier to work with.
Also, I'm not sure how your table is setup but make sure that your "CreateOn" field is the Range key and that you are using Query, not Scan. Using the Scan operation doesn't scale well.
In my current date form input, I have the parameter:
'maxYear' => date('Y')
This lets me limit the max year to this year, but I also need to limit the date selection so users cannot select a date in the future. Using maxYear only allows limiting the year, but I also need months and days.
That's not something you can do with the Form Helper (or the HTML form options even if you'd wrote them manually).
The problem:
If you limit the month to say, 1-7 (if we're currently in July), the user would be unable to select the previous year of any of those months.
The solution:
Use JavaScript onchange validation. When the field(s) change date, check the selected date against your required date range, and give notification if it fails. (see jQuery's .change() documentation if you're using jQuery)
(Then verify on the back-end, as well of course, as JavaScript can easily be manipulated)
In salesforce I can create recurring holidays and based on that in my apex class I want to check whether the current day is holiday or not.
This works fine with normal non recurring holiday. But when I create recurring holiday there is no way to find whether current date will fall on any of the recurring dates.
the holiday object's ActivityDate returns the start date of holiday.
Does anyone have checked the recurring holidays in past for salesforce?
Here is how i would approach this.
Create a function that will take parameters like RECURRENCESTARTDATE , RECURRENCEENDDATEONLY, RECURRENCETYPE, RECURRENCEINTERVAL, RECURRENCEDAYOFWEEKMASK, RECURRENCEDAYOFMONTH, RECURRENCEINSTANCE, RECURRENCEMONTHOFYEAR.
Then this function will loop from start date and for ever iteration it will increment value till date is > today or date is > RECURRENCEENDDATEONLY
in this loop you can check if today's == date calculated above.
once this function is ready pull out list of all recurring holidays.
and call above function on each list item.
let me know if you have any questions.