SAP HANA- working with dates - date

How can I compare current date with stored date in SAP HANA?
When I am using dateFrom > CURRENT_DATE in where clause it gives following error:
CURRENT_DATE is reserved SQL keyword and cannot be used
dateFrom is of type UTCTimestamp.

First check the type of field, if is char, you need to convert this to DATE content, using TO_DATE(YOUR FIELD, MASK),
Then you can use NOW(), to get the current time and date from server.

Related

Checking if today's date is in between the given start date and end date

The code is written in postgresql and run in pgadmin 4.
I am trying to get the id from the pricing table if the current date lies in between the given start date and end date.
I am trying to get the id from the pricing table if the current date lies in between the given start date and end date.
select id
from pricing
where current_Date between start_date>=date '2022-10-19' AND end_date<=date '2022-10-20';
The error raises
operator does not exist: date >= boolean LINE 3: where
current_Date between start_date>=date '2022-10-19'...
Your where condition is essentially someDate between someBoolean and someOtherBoolean, which confuses compiler. Use just this:
where current_Date between date '2022-10-19' AND date '2022-10-20'
between only expects the values:
select id
from pricing
where current_Date between '2022-10-19' AND '2022-10-20';

Crystal Reports: using date from the datatime field as a parameter

I am working on a report that I need to add a date range parameter. The field that I need to use in the datetime field, and I need to use the date portion from the field. I tried using the following, but the report returns no result.
cast(StartDateTime as date) between {?StartDate} and {?EndDate}
For the time being, I am using the Select Expert to sort the date range, but I have to manually enter the date in 'yyyy-mm-dd' format. Is there a way to set up the parameter, so that I can use the calendar to choose the dates?
I recommend to use one parameter field and set it to range and date instead of two.
With this you can use easily this formula:
{StartDateTime} = {?Parameter}
If you set the Parameter to Date instead of DateTime it will automatically check with the start of the day for the first range and the end of the day for the last range.

Change date format with PostgreSQL (AWS Redshift) from 'M/D/YYYY' to 'DD/MM/YYYY' for Qlik Sense date picker extension

I am trying to change the format of a timestamp field to a date field in a certain format with AWS Redshift.
I googled a lot and the common "best practice" that I found was to cast the timestamp to a date and then use to_char to bring it into the right format. In the end I want to use the date field in a Qlik Sense dashboard where it is input for a date picker extension that apparently requires the format DD/MM/YYYY to work.
Current date format in the DB:
9/2/2019 6:38:00 AM (which I would describe as M/D/YYYY H:MM:SS ZZ)
Desired output:
DD/MM/YYYY, resulting in the value 02/09/2019
Current status:
to_char(cast(timestamp_field as date), 'DD/MM/YYYY') --> result: 02/09/2019
However, the date picker extension in Qlik Sense still does not work and I guess that's because the output is a string and not a date. Casting the string to a date returns in an error.
cast(to_char(cast(timestamp_field as date), 'DD/MM/YYYY') as date) as date_picker_date
Connector reply error: SQL##f - SqlState: 57014, ErrorCode: 30,
ErrorMsg: [Amazon][Amazon Redshift] (30) Error occurred while trying
to execute a query: [SQLState 57014] ERROR: Error converting text to
date
I am new to Redshift and would have expected to be able to cast to date with a format string as parameter, but apparently that's not a thing. Can someone enlighten me on how to solve this?
You can try with the timestamp at the beginning of the script of the QlikSense.
It will be at the start of the script. in the Main section as shown below:
SET TimestampFormat='M/D/YYYY h:mm:ss[.fff] TT';
here SET is being used to define the time stamp in that application.
You can try changing here to your requirements.
Else 2 options 1 use a stamp which you have already used or create your own extension from the lib
Stamp use can be like this:
Datestamp_Table:
Load *,
Date(Date#(StringDate,'M/D/YY'),'DD/MMM/YY') as Date;
LOAD * INLINE [
StringDate
8/7/97
8/6/97];
Output will be like this:
Stringdate Date
8/7/97 07/Aug/97
8/6/97 06/Aug/97

How to specify ODATA filter query for the salesforce connector in Microsoft Flow

I'm having difficulty determining the correct format for a date (not a datetime) expression. In this situation, CloseDate from the Opportunity table.
I have tried multiple formats, including quotes, no quotes, timezones, no timezones. I have this working in regular REST queries just using the date in format yyyy-MM-dd without quotes,
A couple of examples..
CloseDate le 2011-12-31
ERROR: Salesforce failed to complete task: Message: FROM Opportunity WHERE (CloseDate <= 2011-12-31T00:00:00.0000000+00:00)\n ^\nERROR at Row:1:Column:6368\nvalue of filter criterion for field 'CloseDate' must be of type date and should not be enclosed in quotes\r\nclientRequestId: 50c8ea4a-bd02-4e95-919c-df02074f3144",
CloseDate ge '2017-01-01'
ERROR: value of filter criterion for field 'CloseDate' must be of type date and should not be enclosed in quotes
CloseDate ge datetime'2017-01-01'
ERROR: inner exception: Unrecognized 'Edm.String' literal
Help! Has anyone worked out how to specify the format for a "date" field in an ODATA filter?
Many thanks in advance.
UPDATE : FEB 11 2020 : I have worked w Microsoft support and this bug is fixed!
You can now filter against date fields or date time fields. Previously filters against date fields failed because flow converted to datetime and sfdc specifies that date fields cannot be queried as datetime
ORIG POST:
I have been poking on this and it looks like msft flow / power automate can only query dateTime fields in salesforce, but not date fields.
i can filter createdDate gt 2020-01-01 with no issues, but cannot query closeDate or any custom date field (flow will not run successfully - throws an error as above). custom datetime field works fine.
the only workaround i have found is to use relative dates - THIS_MONTH, LAST_MONTH etc work fine. (shocking!) that is quite helpful.
however the LAST_N_DAYS:N style does not work, the colon appears to break things.
i have opened a case with microsoft support as it appears that their connector transforms all dates to datetime, and the salesforce docs specify that date fields cannot be queried as datetime
A fieldExpression uses different date formats for date and dateTime fields. If you specify a dateTime format in a query, you can filter only on dateTime fields. Similarly, if you specify a date format value, you can filter only on date fields.:
I had this issues querying the relative days in power flow,power flow had a handy function to resolve this,
LastModifiedDate ge #{getPastTime(7,'Day','yyyy-MM-dd')}
This works well for me

How to add only date like 'DD/MM/YYYY' to timestamp in PostgreSQL?

I'm trying to add only the current date in "DD/MM/YYYY" format in a field of type ' timestamp in PostgreSQL' .
I try:
select to_char(now(),'DD/MM/YYYY') as date;
But PostgreSQL return me:
TIP : You will need to rewrite the expression or apply a type conversion.
There is no such thing as "only the date" in a timestamp field. A timestamp field will store timestamps.
Try using the date type instead. Please read about this here.
Also, please consider using the ISO 8601 format instead. Getting used to it helps in a lot of cases.
Human-readable formats like "DD/MM/YYYY" should only be used for presentation.
If you want to use timestamp fields and insert a human-readable formatted dates, then you are looking for:
to_timestamp('05/04/2016', 'DD/MM/YYYY')
If it is about the current date, then Postgres provides the CURRENT_DATE function, which you may use:
SELECT CURRENT_DATE;
INSERT INTO t (timestamp_field) VALUES (CURRENT_DATE);