Adding Time
am 27.03.2010 18:43:29 von gary
I have a manual input field to add a date on a form. There is another
manual input field to add number of months (This is for a loan agreement).I
am trying to add the two together to get an ending date. I dont think I am
close, can anyone poimt me in the right direction.
$pay_date=($_SESSION['pay_date']);
$loan_length=($_SESSION['loan_length']);
$pay_date = new DateTime($_SESSION['pay_date']);
$end_date = new DateTime($_SESSION['pay_date']) +
($_SESSION['loan_length']);
echo $end_date->format("m-d.Y").'
';
date_add($pay_date + new DateInterval($_SESSION['loan_length']));
echo '
'.$date->format("d-m-Y");
Gary
__________ Information from ESET NOD32 Antivirus, version of virus signature database 4978 (20100326) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Adding Time
am 27.03.2010 18:50:48 von Nilesh Govindrajan
On 03/27/2010 11:13 PM, Gary wrote:
> I have a manual input field to add a date on a form. There is another
> manual input field to add number of months (This is for a loan
> agreement).I am trying to add the two together to get an ending date. I
> dont think I am close, can anyone poimt me in the right direction.
>
>
> $pay_date=($_SESSION['pay_date']);
> $loan_length=($_SESSION['loan_length']);
>
>
> $pay_date = new DateTime($_SESSION['pay_date']);
>
> $end_date = new DateTime($_SESSION['pay_date']) +
> ($_SESSION['loan_length']);
>
> echo $end_date->format("m-d.Y").'
';
>
>
> date_add($pay_date + new DateInterval($_SESSION['loan_length']));
> echo '
'.$date->format("d-m-Y");
>
> Gary
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4978 (20100326) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>
>
Add time in Unix Timestamps. Then format it using strftime.
Also to format inputted date time in the form, check in php manual, to
convert dates to timestamps (i forgot the func. name).
--
Nilesh Govindarajan
Site & Server Administrator
www.itech7.com
मà¥à¤°à¤¾ à¤à¤¾à¤°à¤¤ महान !
मम à¤à¤¾à¤°à¤¤: महतà¥à¤¤à¤® à¤à¤µà¤¤à¥ !
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Adding Time
am 27.03.2010 21:41:21 von gary
Thanks for your reply. This comes from the manual, I have tried to change
to my variables. I am not getting any error messages, but I am not able to
add the $loan_length to the $pay_date.
Thanks again for any help.
gary
$pay_date=($_SESSION['pay_date']);
$loan_length=($_SESSION['loan_length']);
$orgDate=($_SESSION['pay_date']);
$mth=($_SESSION['loan_length']);
function add_date($orgDate,$mth){
$cd = strtotime($orgDate);
$end_date = date('Y-m-d',
mktime(0,0,0,date('m',$cd)+$mth,date('d',$cd),date('Y',$cd)) );
return $end_date;
}
echo $orgDate ."
";
echo $end_date ."
";
echo $pay_date ."
";
echo $loan_length;
?>
"Nilesh Govindarajan" wrote in message
news:4BAE4578.9080006@itech7.com...
> On 03/27/2010 11:13 PM, Gary wrote:
>> I have a manual input field to add a date on a form. There is another
>> manual input field to add number of months (This is for a loan
>> agreement).I am trying to add the two together to get an ending date. I
>> dont think I am close, can anyone poimt me in the right direction.
>>
>>
>> $pay_date=($_SESSION['pay_date']);
>> $loan_length=($_SESSION['loan_length']);
>>
>>
>> $pay_date = new DateTime($_SESSION['pay_date']);
>>
>> $end_date = new DateTime($_SESSION['pay_date']) +
>> ($_SESSION['loan_length']);
>>
>> echo $end_date->format("m-d.Y").'
';
>>
>>
>> date_add($pay_date + new DateInterval($_SESSION['loan_length']));
>> echo '
'.$date->format("d-m-Y");
>>
>> Gary
>>
>> __________ Information from ESET NOD32 Antivirus, version of virus
>> signature database 4978 (20100326) __________
>>
>> The message was checked by ESET NOD32 Antivirus.
>>
>> http://www.eset.com
>>
>>
>>
>>
>
> Add time in Unix Timestamps. Then format it using strftime.
>
> Also to format inputted date time in the form, check in php manual, to
> convert dates to timestamps (i forgot the func. name).
>
> --
> Nilesh Govindarajan
> Site & Server Administrator
> www.itech7.com
> ???? ???? ???? !
> ?? ????: ?????? ???? !
>
> __________ Information from ESET Smart Security, version of virus
> signature database 4978 (20100326) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
>
__________ Information from ESET Smart Security, version of virus signature database 4978 (20100326) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Adding Time
am 27.03.2010 22:14:07 von Joseph Masoud
--0014852d24c1ad78260482cec23b
Content-Type: text/plain; charset=ISO-8859-1
On Sat, Mar 27, 2010 at 8:41 PM, Gary wrote:
> [...]
>
>
>
> $pay_date=($_SESSION['pay_date']);
>
>
> $loan_length=($_SESSION['loan_length']);
>
> $orgDate=($_SESSION['pay_date']);
> $mth=($_SESSION['loan_length']);
> function add_date($orgDate,$mth){
> $cd = strtotime($orgDate);
> $end_date = date('Y-m-d',
> mktime(0,0,0,date('m',$cd)+$mth,date('d',$cd),date('Y',$cd)) );
> return $end_date;
> }
> echo $orgDate ."
";
> echo $end_date ."
";
> echo $pay_date ."
";
> echo $loan_length;
> ?>
You access form element values via the $_POST superglobal, why are you using
$_SESSION?
http://php.net/manual/en/reserved.variables.post.php
--0014852d24c1ad78260482cec23b--
Re: Adding Time
am 27.03.2010 22:17:27 von gary
It is a multi page form with all information being writting to the database
via the $_SESSION's.
Gary
"Yousif Masoud" wrote in message
news:k2qbffe24ad1003271414za1377a2dsb0e4a2d23d4119c9@mail.gm ail.com...
> On Sat, Mar 27, 2010 at 8:41 PM, Gary wrote:
>
>> [...]
>>
>>
>>
>> $pay_date=($_SESSION['pay_date']);
>>
>>
>> $loan_length=($_SESSION['loan_length']);
>>
>> $orgDate=($_SESSION['pay_date']);
>> $mth=($_SESSION['loan_length']);
>> function add_date($orgDate,$mth){
>> $cd = strtotime($orgDate);
>> $end_date = date('Y-m-d',
>> mktime(0,0,0,date('m',$cd)+$mth,date('d',$cd),date('Y',$cd)) );
>> return $end_date;
>> }
>> echo $orgDate ."
";
>> echo $end_date ."
";
>> echo $pay_date ."
";
>> echo $loan_length;
>> ?>
>
>
> You access form element values via the $_POST superglobal, why are you
> using
> $_SESSION?
>
> http://php.net/manual/en/reserved.variables.post.php
>
>
>
> __________ Information from ESET Smart Security, version of virus
> signature database 4978 (20100326) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
__________ Information from ESET Smart Security, version of virus signature database 4978 (20100326) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Adding Time
am 27.03.2010 23:08:48 von Joseph Masoud
--001636025df13b6e1d0482cf8647
Content-Type: text/plain; charset=ISO-8859-1
On Sat, Mar 27, 2010 at 8:41 PM, Gary wrote:
> [...]
>
>
>
> $pay_date=($_SESSION['pay_date']);
>
>
> $loan_length=($_SESSION['loan_length']);
>
> $orgDate=($_SESSION['pay_date']);
> $mth=($_SESSION['loan_length']);
> function add_date($orgDate,$mth){
> $cd = strtotime($orgDate);
> $end_date = date('Y-m-d',
> mktime(0,0,0,date('m',$cd)+$mth,date('d',$cd),date('Y',$cd)) );
> return $end_date;
> }
> echo $orgDate ."
";
> echo $end_date ."
";
> echo $pay_date ."
";
> echo $loan_length;
> ?>
Can you echo $pay_date and show us how the input date is formatted? eg.
2010-03-27
Can you also show us the output of the last four echo statements?
This works for me:
function addMonthsToDate($start,$month)
{
return strtotime("$start + $month months");
}
$test = addMonthsToDate("2010-03-26",3);
echo date('Y-m-d',$test); // gives 2010-06-26
--001636025df13b6e1d0482cf8647--
Re: Adding Time
am 27.03.2010 23:26:38 von gary
I have copied the echo and the code, for clarity I have echo'd 1,2,3, etc
to see which is working.
Thank you for your help. Hope this is clear.
Gary
$loan_length=($_SESSION['loan_length']); //is set to 36 months
$pay_date=($_SESSION['pay_date']); //is set to 01-05-2010
$orgDate=($_SESSION['pay_date']);
$mth=($_SESSION['loan_length']);
$end_date=date('m-d-Y',strtotime('$mth')) + date('m-d-Y',
strtotime('$pay_date'));
$loan_length=date('m-d-Y');
$mthdate=date('m-d-Y',
function add_date($orgDate,$mth){
$cd = strtotime($orgDate);
return $end_date;
}
$orgDate=date("m",strtotime('$loan_length'));
echo 1 ."
";
echo $mth ."
";
echo 2 ."
";
echo $end_date ."
";
echo 3 ."
";
echo $pay_date ."
";
echo 4 ."
";
echo $loan_length."
";
echo 5 ."
";
echo $orgDate."
";
?>
***Page output***
1
36 //this is correct
2
24 //this is not
3
01-05-2010
4
03-27-2010
5
12 //this is not
"Yousif Masoud" wrote in message
news:x2sbffe24ad1003271508xb1f414fck7b6eb93a6cd79c8f@mail.gm ail.com...
> On Sat, Mar 27, 2010 at 8:41 PM, Gary wrote:
>
>> [...]
>>
>>
>>
>> $pay_date=($_SESSION['pay_date']);
>>
>>
>> $loan_length=($_SESSION['loan_length']);
>>
>> $orgDate=($_SESSION['pay_date']);
>> $mth=($_SESSION['loan_length']);
>> function add_date($orgDate,$mth){
>> $cd = strtotime($orgDate);
>> $end_date = date('Y-m-d',
>> mktime(0,0,0,date('m',$cd)+$mth,date('d',$cd),date('Y',$cd)) );
>> return $end_date;
>> }
>> echo $orgDate ."
";
>> echo $end_date ."
";
>> echo $pay_date ."
";
>> echo $loan_length;
>> ?>
>
>
> Can you echo $pay_date and show us how the input date is formatted? eg.
> 2010-03-27
>
> Can you also show us the output of the last four echo statements?
>
> This works for me:
>
> function addMonthsToDate($start,$month)
> {
> return strtotime("$start + $month months");
> }
>
> $test = addMonthsToDate("2010-03-26",3);
>
> echo date('Y-m-d',$test); // gives 2010-06-26
>
>
>
> __________ Information from ESET Smart Security, version of virus
> signature database 4978 (20100326) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
__________ Information from ESET Smart Security, version of virus signature database 4978 (20100326) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Adding Time
am 27.03.2010 23:36:13 von Joseph Masoud
--0014852d24c143a6940482cfe804
Content-Type: text/plain; charset=ISO-8859-1
On Sat, Mar 27, 2010 at 10:26 PM, Gary wrote:
> [...]
>
> strtotime('$pay_date'));
>
> [...]
>
If you want the value of $pay_date to be the argument of strtotime, you need
to enclose it in double quotes (do the same for all other occurrences).
Try:
strtotime("$pay_date");
[...]
When a string is
specified in double quotes or with heredoc,
variablesare
parsed within it.
[...]
from: http://php.net/manual/en/language.types.string.php
Beginning of Variable Parsing Section
--0014852d24c143a6940482cfe804--
Re: Adding Time
am 27.03.2010 23:48:30 von Joseph Masoud
--00c09ffb52a83100b00482d014a8
Content-Type: text/plain; charset=ISO-8859-1
On Sat, Mar 27, 2010 at 10:26 PM, Gary wrote:
> [...]
>
$end_date=date('m-d-Y',strtotime('$mth')) + date('m-d-Y',
> strtotime('$pay_date'));
>
> [...]
Try changing above to:
$end_date = date('m-d-Y',strtotime("$pay_date + $mth months"));
I think your mail client took it out of the add_date function.
--00c09ffb52a83100b00482d014a8--
Re: Adding Time
am 27.03.2010 23:52:08 von gary
Perfect, thank you very much for your help!
Gary
"Yousif Masoud" wrote in message
news:x2tbffe24ad1003271548l65cb6e65qd8f35ae0636eb2b@mail.gma il.com...
> On Sat, Mar 27, 2010 at 10:26 PM, Gary wrote:
>
>> [...]
>>
>
> $end_date=date('m-d-Y',strtotime('$mth')) + date('m-d-Y',
>> strtotime('$pay_date'));
>>
>> [...]
>
>
> Try changing above to:
>
> $end_date = date('m-d-Y',strtotime("$pay_date + $mth months"));
>
> I think your mail client took it out of the add_date function.
>
>
>
> __________ Information from ESET Smart Security, version of virus
> signature database 4978 (20100326) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
__________ Information from ESET Smart Security, version of virus signature database 4978 (20100326) __________
The message was checked by ESET Smart Security.
http://www.eset.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Adding Time
am 31.03.2010 14:36:33 von Anshul Agrawal
--000e0cd3559a12395e048317ffd2
Content-Type: text/plain; charset=ISO-8859-1
On Sun, Mar 28, 2010 at 4:22 AM, Gary wrote:
> Perfect, thank you very much for your help!
>
> Gary
>
>
> "Yousif Masoud" wrote in message
> news:x2tbffe24ad1003271548l65cb6e65qd8f35ae0636eb2b@mail.gma il.com...
> > On Sat, Mar 27, 2010 at 10:26 PM, Gary wrote:
> >
> >> [...]
> >>
> >
> > $end_date=date('m-d-Y',strtotime('$mth')) + date('m-d-Y',
> >> strtotime('$pay_date'));
> >>
> >> [...]
> >
> >
> > Try changing above to:
> >
> > $end_date = date('m-d-Y',strtotime("$pay_date + $mth months"));
> >
> > I think your mail client took it out of the add_date function.
> >
> >
> >
> > __________ Information from ESET Smart Security, version of virus
> > signature database 4978 (20100326) __________
> >
> > The message was checked by ESET Smart Security.
> >
> > http://www.eset.com
> >
> >
>
>
>
> __________ Information from ESET Smart Security, version of virus signature
> database 4978 (20100326) __________
>
> The message was checked by ESET Smart Security.
>
> http://www.eset.com
>
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Be cautious while using this.
$mth = 1;
$pay_date = "2010-01-31";
$end_date = date('m-d-Y',strtotime("$pay_date + $mth months"));
echo $end_date; //03-03-2010, will take you to March
Thanks,
Anshul
--000e0cd3559a12395e048317ffd2--