Power Automate Date Condition - filter

I need help with writing this logic in Power Automate
I have 3 date columns which I need to check if they are less than the CurrentDate
if they are, change the status column to expired.
If Date_1 < CurrentDate change the status "Expired"
If Date_2 < CurrentDate change the status "Expired"
If Date_3 < CurrentDate change the status "Expired"
Either of the date columns can be empty so I need to account for that.
Either of the date columns can be >= CurrentDate in that case the status stays "Active"

Related

Using current system month inside date functions

I am trying to write a query in Noetix that is pulling data from Oracle EBS. The query will have a column that checks to see if the date range of a field value of each record is within the current month then, if so, return another value. For example, the field value might be "23 JUN 2022", and I want to check to see if this date is within the "current" month.
So that I don't have to manually edit the report every time a month turns, I want the function to be 'rolling' where it checks the system time for the current month instead of me hard coding it in. I have the following expression, which works, but is static:
case
when
"TABLE1"."Scheduled_Date" >= TO_DATE('01 Jun 2022','DD Mon YYYY') AND
"TABLE1"."Scheduled_Date" < TO_DATE('01 Jul 2022','DD Mon YYYY') THEN
"TABLE1"."Selling_Price"
ELSE
TO_NUMBER('0')
END
How do I replace "Jun" and "Jul" in the expression above with a SYSDATE function that returns the current system month (for Jun), and the current system month +1 (for Jul)? I am experienced at MS Access SQL, but Oracle SQL is new to me. I can't figure out the proper syntax.
for the 1st day of the actual month you can use
add_months(last_day(trunc(sysdate))+1, -1)
for the 1st day of the next month you can use
last_day(trunc(sysdate))+1
There are various options you might choose; here's one of them (I'm setting date format so that you'd recognize values being returned; you don't have to do that):
SQL> alter session set nls_date_format = 'dd.mm.yyyy hh24:mi:ss';
Session altered.
SQL> select trunc(sysdate, 'mm') first_of_this_month,
2 add_months(trunc(sysdate, 'mm'), 1) first_of_next_nonth
3 from dual;
FIRST_OF_THIS_MONTH FIRST_OF_NEXT_NONTH
------------------- -------------------
01.06.2022 00:00:00 01.07.2022 00:00:00
SQL>
Applied to your code:
case when "TABLE1"."Scheduled_Date" >= trunc(sysdate, 'mm')
AND "TABLE1"."Scheduled_Date" < add_months(trunc(sysdate, 'mm'), 1)
THEN
"TABLE1"."Selling_Price"
ELSE
TO_NUMBER('0')
END

How do i get result by comparing Date column and Time column when Date and Time column are separate columns in Laravel

I want to fetch events based on their end_date and end_time from events table. So i need to fetch those events only which are in the future. So if current date and time is greater than end_date and end_time then then it should not fetch those records because the the date and time has passed.
I have done so far :
$today = Carbon::now();
return $query->where('end_date', '>=', today()->format('Y-m-d'))
->where('end_time', '>=', $today->toTimeString());
But this code will not work as expected.
Lets suppose The record is end_date = 2020-02-05 and end_time = 08:00:00 and right now it's 20:10:00 in my town. So As i can see this is a future record and i want it to be fetched but it will not fetch because of where('end_time) because 08:00:00 >= 20:10:00 is false hence this solution will not work
How can i write a query where i will be able to check first if date is today then only check time.
Thanks in advance.
You can try to combine the two fields at a database level (assuming you are using MySql):
return $query->whereRaw('TIMESTAMP(`end_date`,`end_time`) >= ?', [now()->toDateTimeString()]);
You have to change the two columns and use just one column of the type datetime and then you can get the date or the time in the code

Oracle historical reporting - what was the row at a point in time

I have been asked to run a report of the state of our assets at a fixed point in time (1st Jan 2019).
The way this database has been written is that the asset has its own table with current info and then for various bits of data there is also the history of that info changing, each bit is stored its own "history" table with a start and end date. So for example one of the bits of info is the asset class - the asset table will have a field that contains the current asset class and then if that class has changed in the past then there will be rows in the asset_history table with start and end dates. Something like...
AssetID AssetClass StartDate EndDate
------- ---------- --------- -------
1 1 12-12-87 23-04-90
1 5 23-04-90 01-02-00
1 2 01-02-00 27-01-19
1 1 27-01-19
So this asset has changed classes a few times but I need to write something to be able to check, for each asset, and work out which class was the active class as at 1st Jan. For this example that would be the second-from last row as it changed to class 2 back in 2000 and then after 1st Jan 2019 it became a class 1.
And to make it more complicated I will need this for several bits of data but if I can get the notion of how to do it right then I'm happy to translate this to the other data.
Any pointers would be much appreciated!
I usually write this like
select assetClass
from history_table h
where :point_in_time >= startDate
and (:point_in_time < endDate
or endDate is null)
(assuming that those columns are actually date type and not varchar2)
between always seems tempting, but it includes both endpoints, so you'd have to write something like :point_in_time between startDate and (endDate - interval '1' second)
EDIT: If you try to run this query with a point_in_time before your first start_date, you won't get any results. That seems normal to me, but maybe instead you want to pick "the first result which hasn't expired yet", like this:
select assetClass
from history_table h
where (:point_in_time < endDate
or endDate is null)
order by startDate asc
fetch first 1 row only

How do I update the time in oracle sql?

I need a query to update a time in an appointment date by keeping the date but changing the time.
For example
10-Feb-2016 09:00:00
and i want to change it to 10-Feb-2016 10:00:00.
Update Appointment
set vdate = '10:00:00'
where vdate= '10-Feb-2016'
I get the "0 row has been updated'. Not sure if i'm missing something.
Thanks in advance.
You can use trunc() which sets the time part of a DATE (or TIMESTAMP) to 00:00:00, then add the 10 hours to it:
Update Appointment
set vdate = trunc(vdate) + interval '10' hour
where trunc(vdate) = DATE '2016-02-10'
This would change all rows that have a date 2016-02-10. If you only want to do that for those that are at 09:00 (ignoring the minutes and seconds) then just add one hour to those rows
Update Appointment
set vdate = trunc(vdate) + interval '1' hour
where trunc(vdate, 'hh24') = timestamp '2016-02-10 09:00:00'
trunc(vdate, 'hh24') will set the minutes and seconds of the date value to 00:00, so that the comparison with 2016-02-10 09:00:00 works properly.
Unrelated, but: do not rely on implicit data type conversion. '10-Feb-2016' is a string value, not a DATE literal. To specify a date either use an ANSI DATE literal (as I have done in the above statement) or use the to_date() function with a format mask to convert a string literal to a proper date value.
Your statement is subject to the evil implicit data type conversion and will fail if the SQL client running the statement uses a different NLS setting (it will fail on my computer for example)
If what you want to do is add an hour to a date, then you can do:
Update Appointment
set vdate = vdate + 1/24
where vdate = to_date('10/02/2016 09:00', 'dd/mm/yyyy hh24:mi');
since in Oracle, date differences are measured in number of days, and an hour is 1/24th of a day.
If what you want to do is specify an exact time (e.g. to 10:25:48), then you could do the following instead:
Update Appointment
set vdate = trunc(vdate) + 10/24 + 25/(24*60) + 48/(24*60*60)
where vdate = to_date('10/02/2016 09:00', 'dd/mm/yyyy hh24:mi');
Bear in mind that these updates will update all rows that have a date of 10th Feb 2016 at 9am. You'd need to change your query's where clause if you wanted to specify a more specific row or set of rows.
Try like this.
UPDATE MyTable
SET MyDate = DATEADD(HOUR, 4, CAST(CAST(MyDate AS DATE) AS DATETIME))
or
UPDATE MyTable
SET MyDate = DATEADD(HOUR, 4, CAST(FLOOR(CAST(MyDate AS FLOAT)) AS DATETIME))

how to subtract date from another date in oracle

Let's say I am having a table orders and having column
LastUpdatedDate, status.
What i am trying to do is -
picks all the Order which are ā€˜Pā€™ status and lastupdate is two days
back from current date
.
can any one help me in writing a query to get my result.
Thanks
try
select * from yourtable
where status = 'P'
and LastUpdatedDate < sysdate - 2

Resources