Jump to content


Photo

jumping dates 30 days


  • Please log in to reply
4 replies to this topic

#1 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 18 September 2006 - 07:28 PM

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.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 18 September 2006 - 07:42 PM

<?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
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 18 September 2006 - 08:42 PM

ah ok, thanks.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 18 September 2006 - 10:54 PM

I did that, and when i used today's date, it was today's
it returned the date
1999-12-30

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 18 September 2006 - 11:03 PM

<?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
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users