Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 21st, 2005, 06:40 PM
Authorized User
 
Join Date: Jul 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default PHP date arithmetic

I need to be able to determine an expiration date as being today plus a given subscription term. Given that:

$curdate=date("Ymd");
$term=365;

Why does the following not work? And what would?

$expdate= date($curdate, mktime(0, 0, 0, date("m"), date("d")+$term, date("y")));


 
Old December 23rd, 2005, 07:12 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

What're you doing? Try this:
Quote:
quote:
<?php
$curdate = date("Ymd");
$term = 365;
$expdate = date( "Ymd", mktime(0, 0, 0, date("m"), date("d")+$term, date("y")) );
echo $curdate . "<br>" . $expdate;
?>
`~@#\^%&*/\.<.\/-|+|_!:;..=?>
Students' finances
 
Old December 23rd, 2005, 03:08 PM
Authorized User
 
Join Date: Jul 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you. Apparently my problem was in not understanding the "format" field in the "date" command. With your help, it works perfectly.

 
Old February 12th, 2009, 02:21 AM
Registered User
 
Join Date: Feb 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Even shorter...

You might also try this...

$expdate = date("Ymd",strtotime("+$term days"));
 
Old February 12th, 2009, 02:54 PM
Authorized User
 
Join Date: Dec 2008
Posts: 50
Thanks: 1
Thanked 5 Times in 5 Posts
Default

much better if you use strtotime function ...





Similar Threads
Thread Thread Starter Forum Replies Last Post
Arithmetic overflow error gregalb Reporting Services 1 June 24th, 2008 02:42 PM
Basic- Making a template call / Date Arithmetic presack XSLT 2 August 3rd, 2007 01:33 PM
date arithmetic pcase XSLT 4 June 8th, 2007 09:58 AM
arithmetic with ASP VBScript dcarroll Classic ASP Basics 2 October 7th, 2005 09:14 AM
arithmetic overflow problem flyfish SQL Server 2000 4 July 12th, 2005 04:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.