deluge script - date comparison operator versus current date - zoho

I wrote the following deluge script, whene I am comparing the date of joining of the employee with the current date but i get a NULL response
Date of joining looks like 20-Nov-1979
searchMap1 = Map();
searchMap1.put("searchField","Dateofjoining");
searchMap1.put("searchOperator",">");
searchMap1.put("searchText",now);
Is there a solution to this?

I've managed to get my response from the application support team (in this case it is the zoho suite)
searchMap1 = Map();
searchMap1.put("searchField","Dateofjoining");
searchMap1.put("searchOperator","After");
searchMap1.put("searchText",zoho.currentdate.toString("dd-MMM-yyyy");

if you're comparing date strings it's easiest to print out both and then convert them to dates depending on their format:
info date_one; //output 20-01-2022
info date_two; //output 20/01/2022
if (date_one.toDate("dd-MM-yyyy") > date_two.toDate("dd/MM/yyyy")
{
//do this
}

Related

How to get only first part of the date ('DD') from an entire date?

I've converted a date into string. Now, I want to parse a string to get the DD part from DD-MM-YYYY.
For e.g.
If the date is 03-05-2017 (DD-MM-YYYY) then the goal is to get only first part of the string i.e. 03 (DD).
You've tagged this question as a ServiceNow question, so I assume you're using the ServiceNow GlideDateTime Class to derive the date as a string. If that is correct, did you know that you can actually derive the day of the month directly from the GlideDateTime object? You can use the getDayOfMonth(), getDayOfMonthLocalTime(), or getDayOfMonthUTC().
You could of course, also use String.prototype.indxOf() to get the first hyphen's location, and then return everything up to that location using String.prototype.slice().
Or, if you're certain that the day of the month in the string will contain an initial zero, you can simply .slice() out a new string from index 0 through index 2.
var date = '03-05-2017';
var newDate = date.slice(0, 2);
console.log(newDate); //==>Prints "03".
var alternateNewDate = date.slice(0, date.indexOf('-'));
console.log(alternateNewDate); //==>Prints "03".

Filter Date for Reporting

I am currently working with reports in Navision by a "book sales" currently use 2 variables "Date" one for the start and one for the end of the filter, but I wonder if you can only use a single variable where the user directly enter "month" and "year". Thank You!
If you are setting the filter with SETRANGE you need two values. But if you use SETFILTER you can use a string with a date filter like this:
010115..103115
p1..p3
and the just:
DateField.SETFILTER(filterstring);
Yes, when the user put the month and year data you by code transform this info in date values example:
Variables from and to = date
from := DMY2DATE(1, Month, Year);
EVALUATE(to, FORMAT(CALCDATE('+1M', Desde) -1));
YourTable.SETRANGE("Posting Date", from, to);

Calculating Age by custom Program

There is one POST request which submits both Date of Birth & Age.
I found the Date of Birth from previous request, extracted it through Regular Expression Extractor, and passing the Variable in the POST request.
But I did not found the Age from the previous request. Tried figuring out the Age element through Firebug also. But it's not located, due to this field is auto calculated by the Date of Birth field and also the field is read-only.
How do I get the value of Age field?
Possible solution could be using some Jmeter in-built function or by writing some Program in any Scripting Language. But I do not know how to do it in Jmeter.
Thanks in advance.
Given that you have variable i.e. "birthdate" with the value of "1970-05-15" you can figure out person's age with the Beanshell PreProcessor as follows:
Add a Beanshell PreProcessor as a child of the sampler which needs to pass birth date and age.
Put the following code into the PreProcessor's "Script" area
import java.text.SimpleDateFormat;
String birthDate = vars.get("birthDate");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
Date dateOfBirth = sdf.parse(birthDate);
Calendar dob = Calendar.getInstance();
dob.setTime(dateOfBirth);
Calendar today = Calendar.getInstance();
int age = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR);
if (today.get(Calendar.MONTH) < dob.get(Calendar.MONTH)) {
age--;
} else if (today.get(Calendar.MONTH) == dob.get(Calendar.MONTH)
&& today.get(Calendar.DAY_OF_MONTH) < dob.get(Calendar.DAY_OF_MONTH)) {
age--;
}
vars.put("age",String.valueOf(age));
You will be able to refer calculated age as ${age}
See SimpleDateFormat JavaDoc for explanation of "yyyy-mm-dd" pattern and information on how to define the one which matches your application date and time format and How to use BeanShell: JMeter's favorite built-in component guide to learn about scripting in JMeter.
Without seeing the response I can't say whether is can be extracted or not. A viable workaround would be to add a Post Processor to the request that the DOB is extracted from (this can be a jsr223 or beanshell) from there you can grab the DOB as such:
String dob = vars.get{"dateOfBirth"}
From there you will need to parse this into a date and compare it with the current date to get the age. You then need to put the "Age" variable so JMeter can access it.
vars.put("age", String.valueOf(age))

How can I compare 2 dates in a Where statement while using NoRM for MongoDB on C#?

I have a table in Mongo. One of the fields is a DateTime. I would like to be able to get all of the records that are only for a single day (i.e. 9/3/2011).
If I do something like this:
var list = (from c in col
where c.PublishDate == DateTime.Now
select c).ToList();
Then it doesn't work because it is using the time in the comparison. Normally I would just compare the ToShortDateString() but NoRM does not allow me to use this.
Thoughts?
David
The best way to handle this is normally to calculate the start datetime and end datetime for the date in question and then query for values in that range.
var start = DateTime.Now.Date;
var end = start.AddDays(1);
...
But you'd also be well advised to switch to the official C# driver now. You should also use UTC datetimes in your database (but that gets more complicated).

Get the the most recent and the one before the most recent item

I have a table with many anniversaries : Date + Name.
I want to display the next anniversary and the one after with Linq.
How can i build the query ?
I use EF
Thanks
John
Just order by date and then use the .Take(n) functionality
Example with a list of some objects assuming you want to order by Date then Name:
List<Anniversaries> annivDates = GetAnnivDates();
List<Anniversaries> recentAnniv = annivDates.OrderBy(d => d.Date).ThenBy(d => d.Name).Take(2).ToList();
If the anniversaries are stored in regular DateTime structs, they may have the 'wrong' year set (i.e. wedding or birth year). I suggest writing a function which calculates the next date for an anniversary (based on the current day) like:
static DateTime CalcNext(DateTime anniversary) {
DateTime newDate = new DateTime(DateTime.Now.Year, anniversary.Month, anniversary.Day);
if (newDate < DateTime.Now.Date)
newDate = newDate.AddYear(1);
return newDate;
}
Then you proceed with sorting the dates and taking the first two values like described in the other postings:
(from e in anniversaries orderby CalcNext(e.Date) select e).Take(2)

Resources