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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.