Question: I am running a people code written below and getting error `ORA-01830: date format picture ends before converting entire input string`

I need to calculate the time difference in minutes for the two dates on different pages.

```
Component datetime &datetimefrom;
Component datetime &datetimeto;

SQLExec("SELECT to_char(sysdate, 'YYYY-MM-DD HH24-MI-SS') FROM DUAL", &datetimefrom);
SQLExec("SELECT to_char(sysdate, 'YYYY-MM-DD HH24-MI-SS') FROM DUAL", &datetimeto);
SQLExec("Select %DateTimeDiff(:1, :2) from dual", &datetimefrom, &datetimeto, &Diff);

```

Please suggest how to solve this?

Answer: 
I'm not that good in PeopleSoft, but my Oracle experience tells me you are doing it wrong. 

1. you are calling sysdate both times in a row. This won't give you
much of a difference. Couple of milliseconds, maybe
2. You declared `&datetimefrom` and `&datetimeto` as `datetime`, but at the same time you are selecting character value in it. `SELECT sysdate FROM DUAL` should be enough.
3. In Oracle you can simply subtract dates like:

SQLExec("Select %DATEIN(:1)-%DATEIN(:2) from dual", &datetimefrom, &datetimeto, &Diff);

or 

```
SQLExec("Select %DateTimeDiff((:1),%DATEIN(:2)) from dual", &datetimefrom, &datetimeto, &Diff);

```

if you are sure, that `%DateTimeDiff` gives you the results you want.
When using binds in SQL object , you absolutely need to encapsulate your date and datetime parameters using metaSQL instruction %datein(:1) or %datetimein(:1) to ensure they'll be used correctly.
This will translate to 
 TO\_DATE(:1,'YYYY-MM-DD HH:MI:SS')

So your example would be : 

```
Component datetime &datetimefrom;
Component datetime &datetimeto;

SQLExec("SELECT to_char(sysdate, 'YYYY-MM-DD HH24-MI-SS') FROM DUAL", &datetimefrom);
SQLExec("SELECT to_char(sysdate, 'YYYY-MM-DD HH24-MI-SS') FROM DUAL", &datetimeto);
SQLExec("Select %DateTimeDiff(%datetimein(:1), %datetimein(:2)) from dual", &datetimefrom, &datetimeto, &Diff);

```

&Diff will then contain the difference expressed in minutes between the two input datetime.

More details to be found in [PeopleBooks](http://docs.oracle.com/cd/E15645_01/pt850pbr0/eng/psbooks/tpcl/chapter.htm?File=tpcl/htm/tpcl03.htm)