Jump to content

converting "2008-03-11", "2008-03-13" to array("03-11-2008","03-12-2008","03-...


ultrus

Recommended Posts

Hello,

It's Friday and I'm having a non-unctioning brain. Here's my challenge that will make me most greatful if you have any tips. :)

 

I have a date range from a database that looks like this:

 

$startDate = ""2008-03-11"";

$endDate = ""2008-03-13"";

 

For this to highlight days in my calendar, I need a resulting array of dates that look like this:

 

$dates = array("03-11-2008","03-12-2008","03-13-2008");

 

Any clues on how to go from one format to the other? I'm off to get my mind off this for a sec, then come back and probably figure it out if I beat you to it. heh.

 

Thank you in advance!  :)

Link to comment
Share on other sites

ah this might help as well:

 

$startMonth = substr($startDate,5,2);
$startDay = substr($startDate,8,2);
$startYear = substr($startDate,0,4);

$endMonth = substr($endDate,5,2);
$endDay = substr($endDate,8,2);
$endYear = substr($endDate,0,4);

Link to comment
Share on other sites

I'm probably way off... But again, it's Friday :)

 

How about using explode on the "-" to get the three separate vars (y, m, d) then find the difference in days (psuedocoding this, because accounting for month spannning items would be long). Then loop through and add each date item to the array by concatenating the the variables back together with the incremented day.

 

Or tell me I'm a goofball... Either way, I'm cool with it :)

 

Good Luck

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.