cancel
Showing results for 
Search instead for 
Did you mean: 

Date comparison problem

Former Member
0 Kudos

Hi,

I am getting some date values from a BAPI in the format yyyy-mm-dd. I want to compare a date input against this date.

I have used date/time types for the transactional variables. But here I can declare only in the format yyyy-mm-dd hh:mm:ss. I dont have option to declare values in any other format. How can I compare this date with the dates returned from the BAPI?

Regards,

Divija.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Divija,

Expression Editor Built-In Functions

datecompare(date1, date2)

Datecompare compares two dates and returns an integer that identifies which is the latter date.

If date1 occurs after date2, datecompare returns "-1."

If date1 and date2 are identical, "0" is returned.

If date1 occurs prior to date2, "1" is returned.

Also, I can see that you using the Built-In Function datetoxmlformat. I think your

datetoxmlformat( Repeater_0.Output{/item/START_DATE}, "yyyy-MM-ddT00:00:00" ). is wrong.

Please verify with Mikes Posted: May 28, 2008 1:33 PM.

Regards

Pedro

Edited by: Pedro Iglesias on May 28, 2008 11:14 PM

agentry_src
Active Contributor
0 Kudos

Pedro,

Good catch. I missed that when I read his posting. That is probably the problem.

Mike

Former Member
0 Kudos

Hi Pedro/Kishor,

Problem solved. Thanks for your help. The transaction is working fine now with the date filter.

Now I need to pass values to this transaction from the UI. Before I close the thread, can somebody throw some light on how to do this?

Regards,

Divija.

0 Kudos

Hi Divija,

-Make an Xacute query of your transaction.

-Make a display template as per the requirement.

-Test it through Dynamic Page Generator.

-Make a web page through which you will be passing the input parameters to your query.

-The script part will have following lines of code:

artdocument.AppletName.getQueryObject.setParam(1, <<input1>>);

document.AppletName.getQueryObject.setParam(2, <<input2>>);

document.AppletName.refresh();

(First you have to store the inputs from UI into the variables input1, input2 etc.)

Regards

Khaleel

Former Member
0 Kudos

Hi all,

Thanks for your inputs. Problem is solved now. I could set values for transactional variables from the UI using the following statements:

var StartDate= document.appletname.dateToXMLFormat(SelectedStartDatePass,"yyyy-MM-dd HH:mm:ss");

var EndDate= document.appletname.dateToXMLFormat(SelectedEndDatePass,"yyyy-MM-dd HH:mm:ss");

document.appletname.getQueryObject().setParam(1,StartDate);

document.appletname.getQueryObject().setParam(2,EndDate);

Regards,

Divija.

agentry_src
Active Contributor
0 Kudos

You may want to use SD and ED instead of 1 and 2. The Parameters for a query are string datatype whereas the SD and ED properties are defined as DateTime datatype.

i.e. setParam(SD,StartDate) and setParam(ED,EndDate)

But it will probably work the way you are doing it.

Mike

Former Member
0 Kudos

If you do not use the [SD] and [ED] tokens, you will not be able to leverage the date/time selectors and scrollers in the various applets.

agentry_src
Active Contributor
0 Kudos

Divija,

When you extract a date from the response segment of a BAPI, it is in string format by default. Before you use any of the date expressions, you should explicitly convert it to datetime format using the function datetoxmlformat or dateformat. If you have already done that (and you may have from your statements), you can use datecompare and datediff with the two dates even if they are in different formats. However, if you have one date with HH:mm:ss and one without, you can again use dateformat to strip the HH:mm:ss. Then you can compare them. Or you can go the other way and force the HH:mm:ss to be midnight (default when not displayed). The 'T' between the date and the time is for xml date format. When performing datetime functions inside BLS, try to use xml datetime formats. It will save you a lot of headaches.

datetoxmlformat(BAPI.Response{/XXX}, "yyyy-MM-dd") -- my preferred.

-- Yields dates as 2008-05-28T06:31:34

dateformat(Transaction.Input, "yyyy-MM-ddT00:00:00") -- forces the date to midnight

-- Yields date as 2008-05-28T00:00:00

Hope this helps,

Mike

Former Member
0 Kudos

Hi Michael,

Thanks for your valuable inputs.

Based on your inputs, I am parsing the date returned by BAPI using the statement: datetoxmlformat( Repeater_0.Output{/item/START_DATE}, "yyyy-MM-ddT00:00:00" ). This is assigned to a transactional variable of type datetime.

I want to compare this against another transactional variable of type date time. I am doing it using the statement: (datecompare( Transaction.StartDate , Transaction.InputStartDate ))==1. But somehow this is not having any effect. Any ideas?

Regards,

Divija.

agentry_src
Active Contributor
0 Kudos

Divija,

Put a tracer in front of whatever action block you are using the date compare in.

Then paste the following into the Message of the Tracer:

"Start Date: " & Transaction.StartDate & " Input Start Date: " & Transaction.InputStartDate & " Date Comparison Results: " & stringif(datecompare(Transaction.StartDate, Transaction.InputStartDate)==1," StartDate After InputStartDate", "StartDate on or before InputStartDate")

The results should tell you whether both dates are valid and whether the date comparison is working.

You may have already done something along these lines. If so, then please provide more information on how you are using the datecompare in you expression.

Good luck!

Mike

Former Member
0 Kudos

Hi Divija,

There is a mistake in the format.

Micheal told to use datetoxmlformat and dateformat.

The sysntax is

datetoxmlformat(datetime, xmlformat) ,

dateformat(datetime, fromformat, toformat)

The bapi is returning the date format as yyyy-MM-dd.

The expression should be

datetoxmlformat( Repeater_0.Output{/item/START_DATE}, "yyyy-MM-dd")

This gives you the result as yyyy-MM-ddT00:00:00.

Then you can compare using the datecompare as mentioned by Pedro and Micheal.

Regards,

Kishore

0 Kudos

Hi Divija,

There are different date functions available like datecompare, dateformat, datetoxmlformat etc in link editor.

You can make proper use of those date functions and it will solve your problem.

Regards

Khaleel

Former Member
0 Kudos

Hi,

use the expression tab on the link editor. it contain the so many func regarding the date comparision and date formate.

Thanks

John