Jump to content

dates - create an array of dates until 2 months time


PC Nerd

Recommended Posts

Hi,

 

I wanted to create an array that contained every day until 2 months from $now.  I then want to place this into a drop down box - which i wont have any trouble with.  is there a date function that can do this for me?  also - i wanted to create 3 drop down menues, Day, Hour(24), Minute.  and from teh data pulled from these create a timestamp value. - I may also want to have 12 horu time with an AM or PM selection as well.

 

How woudl i go about this?  i am familiar with teh timestamps and time formatting: from timestamp to text, but i dont know how to go from text to timestamp. 

 

Thanks

The strtotime() function will convert date/time strings to an integer.

 

As for your question about every date until two months from now, you can do something like this:

<?php
$dates = array();
for($i=time();$i< strtotime('+2 months');$i += 86400) // 86400 is the number of seconds in a day
    $dates[] = $i;

echo '<pre>' . print_r($dates,true) . '</pre>'; // dump the raw numbers
foreach ($dates as $date)
     echo date('F j, Y',$date) . "<br>\n";     // format the dates
?>

 

Ken

Archived

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

×
×
  • Create New...

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.