User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 427,094 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,267 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1532 | Replies: 6
Reply
Join Date: Aug 2005
Posts: 17
Reputation: StrikeFreedom is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
StrikeFreedom StrikeFreedom is offline Offline
Newbie Poster

help with PHP script to return dates

  #1  
Apr 24th, 2006
I'm trying to make a script to return the next 5 days for example today is 2006-04-24 and it would create variables with the values of 2006-04-25, 2006-04-26, 2006-04-27, 2006-04-28, 2006-04-29. I thought and using getdate function and add +1~5 to day value but I realized it would bug after the day gets over 30. Any suggestions?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2004
Location: North Carolina
Posts: 27
Reputation: Banderson is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 2
Banderson's Avatar
Banderson Banderson is offline Offline
Light Poster

Re: help with PHP script to return dates

  #2  
May 4th, 2006
Look in the manual for checkdate();
Maybe this will help you.
Reply With Quote  
Join Date: Aug 2005
Posts: 76
Reputation: leelee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
leelee leelee is offline Offline
Junior Poster in Training

Re: help with PHP script to return dates

  #3  
May 5th, 2006
Originally Posted by StrikeFreedom
I'm trying to make a script to return the next 5 days for example today is 2006-04-24 and it would create variables with the values of 2006-04-25, 2006-04-26, 2006-04-27, 2006-04-28, 2006-04-29. I thought and using getdate function and add +1~5 to day value but I realized it would bug after the day gets over 30. Any suggestions?


I don't think checkdate will help greatly. Try mktime() instead.

The php manual entry for "date" reads:
It is possible to use date() and mktime() together to find dates in the future or the past. Example 3. date() and mktime()example

<?php
$tomorrow  = mktime(0, 0, 0, date("m")  , date("d")+1, date("Y"));
$lastmonth = mktime(0, 0, 0, date("m")-1, date("d"),  date("Y"));
$nextyear  = mktime(0, 0, 0, date("m"),  date("d"),  date("Y")+1);
?>
Reply With Quote  
Join Date: May 2006
Posts: 4
Reputation: JD.ua is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
JD.ua JD.ua is offline Offline
Newbie Poster

Re: help with PHP script to return dates

  #4  
May 5th, 2006
Try this function:
int strtotime ( string time [, int now] )
Reply With Quote  
Join Date: Aug 2005
Posts: 76
Reputation: leelee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
leelee leelee is offline Offline
Junior Poster in Training

Re: help with PHP script to return dates

  #5  
May 5th, 2006
Originally Posted by JD.ua
Try this function:
int strtotime ( string time [, int now] )

How will this help in obtaining variables with consecutive dates in them?
Reply With Quote  
Join Date: May 2006
Posts: 4
Reputation: JD.ua is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
JD.ua JD.ua is offline Offline
Newbie Poster

Re: help with PHP script to return dates

  #6  
May 5th, 2006
you can do it like in such way

$dates_array = array();
for ($i=0; $i<5; $i++) {
  $dates_array[] = date('Y-m-d', strtotime("+$i days"));
}
Reply With Quote  
Join Date: Aug 2005
Posts: 76
Reputation: leelee is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
leelee leelee is offline Offline
Junior Poster in Training

Re: help with PHP script to return dates

  #7  
May 5th, 2006
hmmm... ok.

I prefer my solution though!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 5:18 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC