Jump to content

I need help creating a date range with a specific display result.


FramezArt

Recommended Posts

I have an insert record form that has 2 fields: One for the FROM date, and the other for the TO date. When I display them I get the basic formatting that looks like this:

 

12/01/2008 - 12/03/2008

 

What i want is to have them display like this:

 

December 01 - 03, 2008

 

Is this possible?

 

Please Help!

 

Thanks!

Link to comment
Share on other sites

I have an insert record form that has 2 fields: One for the FROM date, and the other for the TO date. When I display them I get the basic formatting that looks like this:

 

12/01/2008 - 12/03/2008

 

You would be much better off using a MySQL DATE datatype to store your dates. You can easily do calculations on it that way, but in the meantime, try something like this:

<?php
$start = '12/01/2008';
$end   = '12/03/2008';
echo date('F j, Y', strtotime($start)), '-', date('F j, Y', strtotime($end));
?>

 

Obviously, this isn't exactly what you're after, but it will work for spans covering multiple months, and you can easily figure out your logic from here.

 

Good luck.

Link to comment
Share on other sites

As somewhat of an extension to obsidian's solution, you could do something such as:

 

<?php
$start = strtotime('12/01/2008');
$end = strtotime('12/03/2008');
if (date('FY', $start) == date('FY', $end))
{
     echo date('F j', $start), ' - ', date('j, Y', $end);
}
else
{
     echo date('F j, Y', $start), ' - ', date('F j, Y', $end);
}
?>

Link to comment
Share on other sites

Thanks So Much!

 

I used this:

 

$data = "$row_rsActAnn[dateFrom]-$row_rsActAnn[dateTo]";

list($dateFromYear, $dateFromMonth, $dateFromDay, $dateToYear, $dateToMonth, $dateToDay) = explode("-", $data);

if ($dateFromMonth =="01") {

$dateFromMonth = "January";

}

if ($dateFromMonth =="02") {

$dateFromMonth = "February";

}

      [...]

 

echo "$dateFromMonth $dateFromDay - $dateToDay , $dateFromYear";

 

 

and it worked great!

 

Thanks so much for your help!

 

K

Link to comment
Share on other sites

Thanks So Much!

 

I used this:

 

$data = "$row_rsActAnn[dateFrom]-$row_rsActAnn[dateTo]";

list($dateFromYear, $dateFromMonth, $dateFromDay, $dateToYear, $dateToMonth, $dateToDay) = explode("-", $data);

if ($dateFromMonth =="01") {

$dateFromMonth = "January";

}

if ($dateFromMonth =="02") {

$dateFromMonth = "February";

}

      [...]

Not to get picky at you, but it may be more logical to set an array of $months, such as:

$months = array(1 => 'January', 2 => 'February', 3 => 'March' ...);

And then later in the script you can check $months[$dateFromMonth].  Instead of having lines and lines of if statements (relatively inefficient).

 

Also, you're aware that this will only handles

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.