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!

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.

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);
}
?>

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

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

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.