Abinitio Interview Question 46

                                     Abinitio Interview Question 46





1  Calculate the difference of date in days

date_difference_days(date2,date1)

date1=(date(YYYY/MM/DD)) '20230521'
date2=(date(YYYY/MM/DD)) '20230523'

2


2  Calucate the Month Start Date and Month End date for the given date

let (date("YYYYMMDD")) l_date = '20230521';

l_month=date_month(l_date)
l_year=date_year(l_date)

month_start_date=(date("YYYYMMDD"))string_concat((string(""))decimal_lpad(l_year,4),(string(""))decimal_lpad(l_month,2),"01");

let string(",")[] leap_year_vec=[vector 31,29,31,30,31,30,31,31,30,31,30,31];
let string(",")[] year_vec=[vector 31,28,31,30,31,30,31,31,30,31,30,31];

let decimal("") is_leap_year = if(l_year/4 ==0) 1 else 0;

if(is_leap_year)
then
month_end_date=(date("YYYYMMDD"))string_concat((string(""))decimal_lpad(l_year,4),(string(""))decimal_lpad(l_month,2),leap_year_vec[l_month-1]);
else
month_end_date=(date("YYYYMMDD"))string_concat((string(""))decimal_lpad(l_year,4),(string(""))decimal_lpad(l_month,2),year_vec[l_month-1]);


3  Calculate the Quarter start date and Quarter End Date for the given date

let string(",")[] quarter_st_date_vec=

let string(",")[int] quarter_st_date_vec= ["0101"+Yr_part,'0104'+Yr_part,'0107'+Yr_part,'0110'+Yr_part];
let string(",")[int] quarter_end_date_vec=["3103"+Yr_part,'3006'+Yr_part,'3009'+Yr_part,'3112'+Yr_part];

if(l_month<4)
{
start_date_q=quarter_st_date_vec[0];
end_date_q=quarter_st_date_vec[0];
}
else
if(l_month<7)
{
start_date_q=quarter_st_date_vec[1];
end_date_q=quarter_st_date_vec[1];
}
if(l_month<10)
{
start_date_q=quarter_st_date_vec[2];
end_date_q=quarter_st_date_vec[2];
}
else
{
start_date_q=quarter_st_date_vec[3];
end_date_q=quarter_st_date_vec[3];
}


4  How to get the difference between 2 times in minutes
let datetime("YYYY/MM/DD") date1='20210521';
let datetime("YYYY/MM/DD") date2='20210519';
datetime_difference_minutes(date1,date2);
2880.0




5 How to convert a string like "2/22/2015 9:54:02 AM" having AM/PM to DateTime datatype?

m_eval '(datetime("MM-DD-YYYY HH24:MI:SS"))(datetime("VMM-DD-YY HH:MI AM", century="2000")(",")) (string("") "3-5-23 3:41 PM"'

"03-05-2023 15:41:00"



For More Abinitio, AWS, Database content please visit my youTube channel.

https://www.youtube.com/@datapundit

@datapundit




Comments

Popular posts from this blog

Abinitio Interview Question # 1 - Write Multiple Files in Abinitio

Next In Sequence in ABinitio | How next_in_sequence() works in MFS