This topic is locked

date add in phprunner

7/14/2005 7:47:34 AM
PHPRunner General questions
author

HI, I have a field where I put number, I would like to know how can calculate and put the resulte in a date field that will add the numeric fild to it. like num.field is 3(for month) and the date field will be 3 + the current date.

I'm quite new with PHP.

Best regards.

Sergey Kornilov admin 7/15/2005

Boris,
you can use calculated field in SQL query. If you use MySQL adddate() function can help you. Here is the example that adds specific number of days to another date field:

select ...,

adddate(`datefield`, interval `addfield` day) as dateadded

from tablename


Here is another example that adds specific number of days to current date.

select ...,

adddate(now(), interval `addfield` day) as dateadded

from tablename


Is that what you looking for?

500296 7/16/2005

not really, let say, that I have a field date1 with the current date, another field witha numeric value like 1...12 for month and the third field date2.

Can I calculate the date2 with date1+the field with numeric value?

Hope you can help me.

Sergey Kornilov admin 7/18/2005

Hi,
you can calculate date2 field value on the fly:

select ...,

adddate(date1, interval `another field` month) as date2

from tablename

501216 8/8/2005

hi again, whre do I put this code? in PHPRunner or ...add.php? whre exacly.

Thanks.

Sergey Kornilov admin 8/9/2005

Hi,
put this code into the box on the Edit SQL query tab (Step5) in PHPRunner.

501217 8/9/2005

ok, I try it, it did not work, I want to when I put the date1 and choose the interval the date2 will be automaticly fill with the calculation.

Sergey Kornilov admin 8/10/2005

Boris,
open ..._add.php file, find the following snippet:

// make SQL string

$strSQL = "insert into ".AddTableWrappers($strTableName)." ";



and insert this line before it:

$avalues["`date2`"]="adddate(".$avalues["`date1`"].", interval ".$avalues["`months`"]." month)";


where date1, months and date2 are exact field names in your table. Field names are case sensitive here.
This will add the number of month you enter in "months" field to "date1" and store the result into "date2" field.

501218 8/10/2005

Finally it works, thanks a lot.

boris

R
rhservice 12/1/2005

We have a field called "Contract_Effective_Date" and one called "Contract_End_Date"

and one called "Term". Your code listed above works perfectly to automatically increment

the End Date by the number of months of the Term. However quite often when changes are

made to the contract on the edit page the Effective Date is changed. Where on the edit page

can this code be placed so that the End Date is updated when the Effective Date is changed

without needing to edit the End Date.
I have tried placing it a few different places but cannot get it to work.
If possible, I would prefer to be able to put the code in on the Edit SQL query tab or in the formatting

so that it is not overwritten whenever the project is rebuilt.
Thank You...............
Larry

Sergey Kornilov admin 12/1/2005

If you like two fields always to have the same value - probably you do not need two fields.

Just calculate one of them on the fly in SQL query.
Is that what you looking for?

B
bantoine 5/3/2009

This is an old post but I would like to know with this code given below to add a date with the month calculation, I would like to know how can I use it and substrack 1 day to the interval. for exemple: date1 01/01/2000, month 2 and date2 =date1+month-1 day like date2= 03-30-2000 instaed of 03/01/2000

Boris,

open ..._add.php file, find the following snippet:

// make SQL string

$strSQL = "insert into ".AddTableWrappers($strTableName)." ";



and insert this line before it:

$avalues["`date2`"]="adddate(".$avalues["`date1`"].", interval ".$avalues["`months`"]." month)";


where date1, months and date2 are exact field names in your table. Field names are case sensitive here.
This will add the number of month you enter in "months" field to "date1" and store the result into "date2" field.

J
Jane 5/4/2009

Hi,
what PHPRunner version do you use?

Where do you want to add this code?

B
bantoine 5/4/2009

I'm using and older version, I think it is the 2.0 version that i bought a few years ago and this code is in xxx_add.php

Hi,

what PHPRunner version do you use?

Where do you want to add this code?

Sergey Kornilov admin 5/4/2009

Unfortunately PHPRunner 2.0 is no longer supported.

B
bantoine 5/4/2009

Can i something similar in the new version of PHPRunner? where date2=date1+interval(month)-1 day? Whre and how can I have it?

Unfortunately PHPRunner 2.0 is no longer supported.

J
Jane 5/5/2009

In the latest versions you can calculate this value in the event on the Events tab in PHPRunner directly.