Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Subtract 1 month from time()?
Old 12-28-2005, 01:49 PM Subtract 1 month from time()?
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
I am using $currenttime = time(); to get the time.

How to I subtract one month, 2 months, 3 months, etc. from the current time?

Thanks,
WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-28-2005, 02:11 PM
capetek's Avatar
Extreme Talker

Posts: 229
Location: Massachusetts
Trades: 0
http://www.phpclasses.org/browse/package/1952.html

Also you could just make variables from using the date() command and then just use - to subtract the month part and echo the total

www.php.net/date
__________________
Anthony LeBoeuf
Cape-Tek IT Solutions

Please login or register to view this content. Registration is FREE

Great hosting at affordable pricing!
capetek is offline
Reply With Quote
View Public Profile Visit capetek's homepage!
 
Old 12-28-2005, 02:33 PM
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
Wow, this is really complicated. Is there a simply way to subtract a month from time()?

WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 12-28-2005, 03:04 PM
capetek's Avatar
Extreme Talker

Posts: 229
Location: Massachusetts
Trades: 0
Ok i made something simple for you, not sure what your using it for but what you described this might work

you can look at www.php.net/date to change the format of the month day and year. here it is in action
http://www.worcesterwideweb.com/work/months.php


PHP Code:
<?php
//the number of months to subtract
$subtractmonths '3';
$fulldate date("m.d.y");
$currentyear =  date("y");
$currentmonth date("m");
$currentday =  date("d");

$subtract date("m")-$subtractmonths;
echo 
"today's date is $fulldate<br>";
echo 
"$subtractmonths months(s) ago it was $subtract.$currentday.$currentyear";

?>
__________________
Anthony LeBoeuf
Cape-Tek IT Solutions

Please login or register to view this content. Registration is FREE

Great hosting at affordable pricing!
capetek is offline
Reply With Quote
View Public Profile Visit capetek's homepage!
 
Old 12-28-2005, 04:05 PM
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
This one doesn't work when the month is near the end of the year. This version adds 3 months. Here is the result, with the code below:
today's date is 12.28.05
3 months(s) from now it will be 15.28.05
<?php
//the number of months to subtract
$addmonths = '3';
$fulldate = date("m.d.y");
$currentyear = date("y");
$currentmonth = date("m");
$currentday = date("d");

$add = date("m")+$addmonths;
echo "today's date is $fulldate<br>";
echo "$addmonths months(s) from now it will be $add.$currentday.$currentyear";

?>
WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 12-28-2005, 04:30 PM
webgrrl's Avatar
Skilled Talker

Posts: 74
Trades: 0
FYI - I think I found something simple. This code will add one month to the current date, and it does adjust correctly:

$date_next_month = date ("m-d-Y", mktime (0,0,0,date("m")+1,date("d"),date("Y")));

WebGrrl
webgrrl is offline
Reply With Quote
View Public Profile
 
Old 12-28-2005, 04:38 PM
capetek's Avatar
Extreme Talker

Posts: 229
Location: Massachusetts
Trades: 0
Yeah, i made a slight mistake. this is what you should use. that way you can control it with a variable


http://www.worcesterwideweb.com/work/months.php
PHP Code:
<?php
// how many months to subtract
$monthssubtract "13";
//get timestamp for past/future date I want
$pf_time strtotime("-$monthssubtract months");
//format the date using the timestamp generated
$actual_date date("F j, Y");
$pf_date date("F j, Y"$pf_time);
echo 
"Today is $actual_date<br>";
echo 
"$monthssubtract months ago it was $pf_date";

?>
__________________
Anthony LeBoeuf
Cape-Tek IT Solutions

Please login or register to view this content. Registration is FREE

Great hosting at affordable pricing!
capetek is offline
Reply With Quote
View Public Profile Visit capetek's homepage!
 
Old 12-31-2005, 05:39 AM
dotcomguy's Avatar
Skilled Talker

Posts: 89
Location: Manchester, UK
Trades: 0
nice solution capetek,
__________________

Please login or register to view this content. Registration is FREE
from just $1.85 per post.
dotcomguy is offline
Reply With Quote
View Public Profile Visit dotcomguy's homepage!
 
Old 12-31-2005, 12:17 PM
Village Idiot's Avatar
Webmaster Talker

Posts: 535
Trades: 0
I thought it was something like
date()-(60*60* 60 *24*31)
being that we are going by seconds, 60*60 is 1 minute, *60 is 1hr, *24 is one day, *31 is one month
__________________
I have the heart of a child, I keep it in a jar on my desk.
Village Idiot is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Subtract 1 month from time()?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28287 seconds with 12 queries