Adding Time

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
gary [ Sa, 27 März 2010 18:43 ] [ ID #2036833 ]

Re: Adding Time

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
Nilesh Govindrajan [ Sa, 27 März 2010 18:50 ] [ ID #2036834 ]

Re: Adding Time

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

<?php


$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" <lists [at] itech7.com> wrote in message
news:4BAE4578.9080006 [at] 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
gary [ Sa, 27 März 2010 21:41 ] [ ID #2036841 ]

Re: Adding Time

--0014852d24c1ad78260482cec23b
Content-Type: text/plain; charset=ISO-8859-1

On Sat, Mar 27, 2010 at 8:41 PM, Gary <gwpaul [at] ptd.net> wrote:

> [...]
> <?php
>
>
> $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--
Joseph Masoud [ Sa, 27 März 2010 22:14 ] [ ID #2036842 ]

Re: Adding Time

It is a multi page form with all information being writting to the database
via the $_SESSION's.

Gary


"Yousif Masoud" <yousif.masoud [at] gmail.com> wrote in message
news:k2qbffe24ad1003271414za1377a2dsb0e4a2d23d4119c9 [at] mail.gm ail.com...
> On Sat, Mar 27, 2010 at 8:41 PM, Gary <gwpaul [at] ptd.net> wrote:
>
>> [...]
>> <?php
>>
>>
>> $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
gary [ Sa, 27 März 2010 22:17 ] [ ID #2036843 ]

Re: Adding Time

--001636025df13b6e1d0482cf8647
Content-Type: text/plain; charset=ISO-8859-1

On Sat, Mar 27, 2010 at 8:41 PM, Gary <gwpaul [at] ptd.net> wrote:

> [...]
> <?php
>
>
> $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--
Joseph Masoud [ Sa, 27 März 2010 23:08 ] [ ID #2036844 ]

Re: Adding Time

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" <yousif.masoud [at] gmail.com> wrote in message
news:x2sbffe24ad1003271508xb1f414fck7b6eb93a6cd79c8f [at] mail.gm ail.com...
> On Sat, Mar 27, 2010 at 8:41 PM, Gary <gwpaul [at] ptd.net> wrote:
>
>> [...]
>> <?php
>>
>>
>> $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
gary [ Sa, 27 März 2010 23:26 ] [ ID #2036845 ]

Re: Adding Time

--0014852d24c143a6940482cfe804
Content-Type: text/plain; charset=ISO-8859-1

On Sat, Mar 27, 2010 at 10:26 PM, Gary <gwpaul [at] ptd.net> 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 <http://www.php.net/manual/en/language.types.string.php> is
specified in double quotes or with heredoc,
variables<http://www.php.net/manual/en/language.variables.php>are
parsed within it.

[...]

from: http://php.net/manual/en/language.types.string.php
Beginning of Variable Parsing Section

--0014852d24c143a6940482cfe804--
Joseph Masoud [ Sa, 27 März 2010 23:36 ] [ ID #2036846 ]

Re: Adding Time

--00c09ffb52a83100b00482d014a8
Content-Type: text/plain; charset=ISO-8859-1

On Sat, Mar 27, 2010 at 10:26 PM, Gary <gwpaul [at] ptd.net> 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--
Joseph Masoud [ Sa, 27 März 2010 23:48 ] [ ID #2036847 ]

Re: Adding Time

Perfect, thank you very much for your help!

Gary


"Yousif Masoud" <yousif.masoud [at] gmail.com> wrote in message
news:x2tbffe24ad1003271548l65cb6e65qd8f35ae0636eb2b [at] mail.gma il.com...
> On Sat, Mar 27, 2010 at 10:26 PM, Gary <gwpaul [at] ptd.net> 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
gary [ Sa, 27 März 2010 23:52 ] [ ID #2036848 ]

Re: Adding Time

--000e0cd3559a12395e048317ffd2
Content-Type: text/plain; charset=ISO-8859-1

On Sun, Mar 28, 2010 at 4:22 AM, Gary <gwpaul [at] ptd.net> wrote:

> Perfect, thank you very much for your help!
>
> Gary
>
>
> "Yousif Masoud" <yousif.masoud [at] gmail.com> wrote in message
> news:x2tbffe24ad1003271548l65cb6e65qd8f35ae0636eb2b [at] mail.gma il.com...
> > On Sat, Mar 27, 2010 at 10:26 PM, Gary <gwpaul [at] ptd.net> 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--
Anshul Agrawal [ Mi, 31 März 2010 14:36 ] [ ID #2037311 ]
PHP » gmane.comp.php.general » Adding Time

Vorheriges Thema: Audiobooks for Developers
Nächstes Thema: how to provide download of files mow in documentroot