Chnage DateFormat in Logic apps - azure-logic-apps

There is a date field in my logic app which i am getting data from finops connector.
In JSON assigning the field.
After Parsing Json and create a csv table assinging like this
Is there a way for me to format the date using formatDateTime in any of the steps above ?
Thanks,
Vivek

I suspect you may have an issue with null values in your array.
You need to check every item and make sure the invoiceDate field contains a valid value.
Something like this will help you if you don't filter them out ...
if(equals(item()['invoiceDate'],null),'',formatDateTime(item()['invoiceDate'], 'dd.MM.yyyy'))
... but you will need to decide on the business logic with those items that do have a null invoice date.

Related

SSRS String to Date conversion (mmddyyyy)

I have a String field in a Dataset in (mmddyyyy) format.
I am trying to convert it into a Date field in SSRS.
I already tried using the below command but I am getting error.
CDate(Fields!LocalTXNDate.Value)
Can anyone please suggest.
While Larnu is correct, the way to do it is to correct the database, sometimes we lowly report makers have no say in making these changes - much less getting a DBA to do it in a reasonable amount of time.
If you can't change the data to be correct, the easiest way to convert and use the field as a date is to add a Calculated Field to the Dataset. Open the dataset properties, click on the Fields tab, Add a Calculated field.
For the Expression, use string functions to parse the field into a generic date format and then CDATE to convert to a date type. Then use the new field for dates. You could also use this in your text box if it's not being reused but it's easier to manipulate the Calculated field.
=CDATE(
RIGHT(Fields!LocalTXNDate.Value, 4) & "-" &
LEFT(Fields!LocalTXNDate.Value, 2) & "-" &
MID(Fields!LocalTXNDate.Value, 3, 2)
)
The problem here isn't SSRS but your data, and that you are using a string based data type to store the data. You need to fix the problem at the source, not at the report level.
The string format you have chosen, MMddyyyy isn't a format that is recognised by default in any of the languages in SQL Server, nor if you explicitly use SET DATEFORMAT, nor does it appear as a style. SET DATEFORMAT MDY; SELECT CONVERT(date,'11172022'); will fail. Therefore you'll need to first do some string manipulation on the data first to be an unambiguous format (yyyyMMdd):
UPDATE YT
SET YourDateColumn = CONVERT(varchar(8),V.DateValue,112)
FROM dbo.YourTable YT
CROSS APPLY (VALUES(TRY_CONVERT(date,CONCAT(RIGHT(YT.YourDateColumn,4),LEFT(YT.YourDateColumn,4)))))V(DateValue);
For any bad values you have, such as '17112022' this will UPDATE the value to NULL; as such you may want to create a new column for the new value, or perhaps a new column to store the value of dates that couldn't be converted.
After you've changed the value to an unambiguous format, then you can ALTER the column:
ALTER TABLe dbo.YourTable ALTER COLUMN YourDateColumn date NULL;
Note that if you have any constraints, you will need to DROP those first, and then reCREATE them afterwards.
Now that the data type of the column is correct, you need not do anything in SSRS, as the data type is correct.

How to write an odata filter in a logic app where field has date time and I just want to use date portion

There is a record in the Salesforce Stay Information which has the following information. "Booked_Check_in_Date_Time__c": "2022-11-05T00:59:00Z"
When I try the following oData filter it does not work.
Booked_Check_in_Date_Time__c eq 2022-11-05
What do I need to change to bring back this record.
This is because you are not using the complete query to filter the results.
What do I need to change to bring back this record.
In your case you need to use the below query format to get the filtered results.
Booked_Check_in_Date_Time__c eq `2022-11-05T00:59:00Z`
RESULTS:
It looked like I needed to use Local_Booked_Checkin_Date__c to achieve what I needed. If I used Booked_Check_in_Date_Time__c I would have to add time to the filter which I did not want to.

postgres sql Query a field with Json data

We have a field in a table that contains JSON object. There are array objects inside the json structure and we would have to extract values specifically from the array. Below is a sample data in the json field
children:[{server:,children:[{server:,newPage:,menuType:3,label:File Tax Forms,url:\/dashboard\/fileTaxForm},{server:,newPage:,menuType:3,label:View Filed Forms,url:dashboard\/viewFiledForms}],
Can you please throw some light on how to extract the values via sql query in the above json object.
Any help on this is much appreciated
Thanks in Advance
When adding the json to your question, it seems to have lost quotes.
If the JSON is inserted as follows
INSERT INTO test VALUES ('{"children":[{"server":"","children":[{"server":"","newPage":"","menuType":3,"label":"File Tax Forms","url":"dashboard/fileTaxForm"},{"server":"","newPage":"","menuType":3,"label":"View Filed Forms","url":"dashboard/viewFiledForms"}]}]}');
into a table defined as follows:
CREATE TABLE test (somejson json);
then you could use a query similar to the following:
SELECT somejson::json->'children'->0->'children'->0->'label' as label, somejson::json->'children'->0->'children'->0->'url' as url FROM test;
to get a result:
label | url
------------------+-------------------------
"File Tax Forms" | "dashboard/fileTaxForm"

Change Datatable Column Value based on condition

I have a datatable in which I have datetime column, in Database DateTime is set as null so it fills with default datetime. Now when I view this datatable in WPF it shows me these dates. Where as I want to make it empty if date is less than 2000-01-01.
foreach (DataRow row in table.Rows)
{
if (row["PROCESSED__DATE"].ToString() != "")
{
string s = Convert.ToDateTime(row["PROCESSED__DATE"].ToString()).ToString("MM/dd/yyyy HH:mm:ss");
if (DateTime.ParseExact(s, "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture)<
DateTime.ParseExact("01/01/2000 00:00:00", "MM/dd/yyyy
HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture
{
row["PROCESSED__DATE"] = "";
}
}
}
I am using this following code to replace datetime column value to empty but I am getting an error on the following line:
row["PROCESSED__DATE"] = "";
The error is String was not recognized as a valid DateTime.Couldn't store, I know this is causing because I am trying to save empty string in DATETIME column. But what I don't know is how can I achieve this without changing datacolumn datatype.
I don't really came up with your code but i'll give you leads to find a solution.
What is your database engine, in almost all you can define the column as Nullable, which mean you will be able to set no value. When you go to find the value you have to use somethig like the FirstOrDefault so if there is no value it is null otherway you get the value
Let's imagine you don't like the first solution, you are using a datatable, not bad but if you want to do a little more and have much more possibilities try using DataGrid, not much complicated, you just need to make something that contains the data and go for the binding magic. With this solution you can do much more and with the Object you'll be able to handle many future potential problems.
If you have any further questions ask it, i'll try the best to help you.
Hoping my answer will help you.
Have a nice day.
Dates are not stored with time zone or format information in the database, it is simply stored as two integers which represent an offset from a zero date.
Your code converts a column that you say is a DateTime to a string and then converts this back to a DateTime and then back to a string again.
string s = Convert.ToDateTime(row["PROCESSED__DATE"].ToString()).ToString("MM/dd/yyyy HH:mm:ss");
This is a pointless exercise, just use the date in its native format and if you want to compare use the DateTime data type.
Additionally, if you can't make the column nullable in the database, then you might want to consider using a constant to represent the empty date.
You can create a date using the date constructors without parsing it from a string.
var baseDate = new Date time(1, 1, 2000);
if (row["PROCESSED__DATE"] < baseDate) { // ... Etc
But still, you aren't going to be able to push anything but a date into the database unless you make the column nullable.
Can you not change the schema to make the column nullable?

isdate function in ssis derived component

Is there any way to check Date(like isDate function in TSQL) column in SSIS package derived column expression after extraction from Sourcefile before loading to target dtabase?
Thanks
there is no built in function but you can run a script task and use vb.net code to check if the column is a date and operate on it as you wish...
I had a similar issue. I had a date/time in a text file, but the field had a dash between the date and the time. I created a derived column to do a replace on the dash:
REPLACE([TimeField], "- ", "")
I then added a convert column to convert the field to a date. I chose to ignore errors. I then added another Derived Column to check if the converted field was NULL, indicating that it could not convert the value. If it was, I had it set to the current date.
There is a a data conversion task you can drop in. Then redirect the rows as needed, either failing the import entirely or redircting the rows that don't work.
Or you could try a conditional split wher eyou cast the field to a date data type and then send the failures along another path (either deleting the records or nulling out the field would be the common action.)
See also http://www.sqlis.com/sqlis/post/Expression-Date-Functions.aspx > "IsDate workaround" for a technique that can be adapted
You can check whether your variable has a date or not using a conditional statement like this:
testDateVariable?true:false
For example, if date > 2 then it is true (and put the date, or format the date as you wish). If it is false, put null (you replace true with the date format and false with null).
All this is in a drived column in SSIS.

Resources