Jump to content

Archived

This topic is now archived and is closed to further replies.

Ninjakreborn

jumping dates 30 days

Recommended Posts

I am recieving a date, formatted like mm-dd-yy
so today would be like
9-18-06
How do I take that, and add 30 days to it, no matter what(also accounting leap year, and some months have less days than others.  Normally I just jump the month up one, but that won't work this time, it has to be 100% accurate, any advice.  I just need to hmm.
Well I need to come up with a date in the future, so when  button is pressed it checks all the things in the database, and checks there date.  Any that are after the current date get deleted.  So if someone was posting ads 2-3 months ago, and the ads are there, and the admin clicks the button, any ones that were dated have already passed.  Like if it expired yesterday, or 2 days ago, or a week ago, then all the ones that are expired then get deleted automatically.
so basically how do I add days to a date, take a formatted date, add a certain number of days to it, and get the date that it'll expire.

Like if I post it today, I need to add 30 days to the date, I need to take todays date, add 30 days to it, and return the new date, so I can have that date as the expiration date.

Share this post


Link to post
Share on other sites
[code]<?php
$date = '9-18-06';
list ($m,$d,$y) = explode ('-', $date);
$date_30 = mktime (0,0,0,$m, $d+30, $y);

echo date ('Y-m-d', $date_30);  // << use this format for db queries
?>[/code]

Share this post


Link to post
Share on other sites
[code]<?php

$date = date('n-d-y');      // << todays date in the input format you specified
list ($m,$d,$y) = explode ('-', $date);
$date_30 = mktime (0,0,0,$m, $d+30, $y);

echo date ('Y-m-d', $date_30);  // --> 2006-10-19
?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.