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. Link to comment https://forums.phpfreaks.com/topic/21179-jumping-dates-30-days/ 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] Link to comment https://forums.phpfreaks.com/topic/21179-jumping-dates-30-days/#findComment-94174 Share on other sites More sharing options...
Ninjakreborn Posted September 18, 2006 Author Share Posted September 18, 2006 ah ok, thanks. Link to comment https://forums.phpfreaks.com/topic/21179-jumping-dates-30-days/#findComment-94212 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 Link to comment https://forums.phpfreaks.com/topic/21179-jumping-dates-30-days/#findComment-94279 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] Link to comment https://forums.phpfreaks.com/topic/21179-jumping-dates-30-days/#findComment-94285 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.