Ninjakreborn Posted September 18, 2006 Share Posted September 18, 2006 I am recieving a date, formatted like mm-dd-yyso today would be like9-18-06How 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 18, 2006 Share Posted September 18, 2006 [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] Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted September 18, 2006 Author Share Posted September 18, 2006 ah ok, thanks. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted September 18, 2006 Author Share Posted September 18, 2006 I did that, and when i used today's date, it was today'sit returned the date1999-12-30 Quote Link to comment Share on other sites More sharing options...
Barand Posted September 18, 2006 Share Posted September 18, 2006 [code]<?php$date = date('n-d-y'); // << todays date in the input format you specifiedlist ($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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.