This topic is locked
[SOLVED]

 Compare date fields on the fly

1/30/2015 1:23:50 PM
PHPRunner General questions
T
taumic author

Hello,

I am using PHPR 8.0.

I have two date fields in a table. When I enter the data or change them (with date-dropdown-boxes), I would like to compare the fields on the fly and issue a message.

For example:
If "Date D" <= "Date A" then message "date wrong".
In "JavaScript OnLoad Event" I have this small script, but nothing happens...



var ctrlAktiv = Runner.getControl(pageid, 'aktivdatum');

var ctrlDeaktiv = Runner.getControl(pageid, 'deaktiv');
function func() {
if(ctrlDeaktiv < ctrlAktiv)

{

alert ('Deaktiv-Datum ist kleiner als Aktiv-Datum!');

}
};
ctrlAktiv.on('keyup', func);

ctrlDeaktiv.on('keyup', func);


I don`t know javascript, where is my mistake?
Thank you and best regards
Taumic

HJB 1/30/2015

For inspiration purposes only ..., here to try to use the best RAD tool v8.0 on this planet rather than to creep on same by JavaScript usage:
DAL method: whereAdd($where, $condition)
Adds new AND condition to the existing WHERE clause.
Syntax
whereAdd($where, $condition)
Arguments
$where - WHERE clause. Example: "ID=19".
$condition - any condition clause. Example: "CustomerID='123'".
Return value
Returns updated WHERE clause.
Example
Add new AND condition to the existing WHERE clause. Use the following code in List page: Before SQL query event:
// all orders placed by customer ALFKI after January 1, 2009
$where = "OrderDate>'2009-01-01' AND CustomerID='ALFKI'";
$strWhereClause = whereAdd ($strWhereClause, $where);

Sergey Kornilov admin 1/30/2015

You need to construct two Date objects in Javascript and compare them See this article for inspiration:

https://freddiemaize.wordpress.com/a-page-hodler/java-world/javascript-datevalidation-compare-two-dates/

T
taumic author 2/4/2015



You need to construct two Date objects in Javascript and compare them See this article for inspiration:

https://freddiemaize.wordpress.com/a-page-hodler/java-world/javascript-datevalidation-compare-two-dates/


.... Now i am doing this in

-ADD PAGE - before record added


$aktiv = $values["aktivdatum"] ; // Date 1

$deaktiv = $values["deaktiv"] ; // Date 2
$aktivDatum = strtotime($aktiv) ;

$deaktivDatum = strtotime($deaktiv) ;
if ( ($deaktivDatum != null) and ( $aktivDatum >= $deaktivDatum ) )

{

$message = "Falscher Datumsbereich: Deaktiv-Datum ist kleiner als Aktiv-Datum!" ;

return false ;

}
return true;


Thank you for your suggestions.
Taumic