Page 1 of 1

Date Convert

Posted: Thu Jul 27, 2006 4:10 pm
by anyday
anyone know how to convert a unix style 07,08 date to english like jan, feb, mar?

Posted: Thu Jul 27, 2006 4:18 pm
by AngryPanda

Posted: Thu Jul 27, 2006 10:06 pm
by anyday
i looked at those 3 functions and none can do what i need them to.

i have a var named $this_month which contains a digit 1-12. i need to have this 1-12 converted into the months spelled out like janurary - december?

Posted: Thu Jul 27, 2006 10:13 pm
by feyd
You could store an array of months, however a combination of two of the funcitons mentioned by AngryPanda will do it as well.

Posted: Fri Jul 28, 2006 12:23 am
by RobertGonzalez
I usually set up a week day array and a month array, like this...

Code: Select all

<?php
/**********************************************************
 * Days of the Week array
 *********************************************************/
$days_array = array(
	"Sunday", 
	"Monday", 
	"Tuesday", 
	"Wednesday", 
	"Thursday", 
	"Friday", 
	"Saturday"
);

/**********************************************************
 * Develop an array of months
 *********************************************************/
$months_array = array(
	1 => 'January',
	2 => 'February',
	3 => 'March',
	4 => 'April',
	5 => 'May',
	6 => 'June',
	7 => 'July',
	8 => 'August',
	9 => 'September',
	10 => 'October',
	11 => 'November',
	12 => 'December');
?>

What's wrong with this?

Posted: Fri Jul 28, 2006 5:02 am
by ronverdonk
You said to have a Unix timestamp (i.e. the result of a PHP time()). Why does the following not give you what you want?

Code: Select all

<?php
echo date("F", time());
?>
It converts a unix timestamp to the full month and that is what you wanted, hmm?

Posted: Fri Jul 28, 2006 8:43 am
by RobertGonzalez
Lets say all you know about the selected month is that it is month number 8. What PHP function tells you the name of the month? date() does not do that.

Posted: Fri Jul 28, 2006 9:01 am
by anyday
everah,

thanks for the help. Im a big newbie here . got any tips on how i would link up my $this_month var with the array?

Still don''t need an array

Posted: Fri Jul 28, 2006 9:20 am
by ronverdonk
Everah wrote:Lets say all you know about the selected month is that it is month number 8. What PHP function tells you the name of the month? date() does not do that.
You can if you just insert the month into a date field, like this:

Code: Select all

$m="08";
$d="2000-$m-04";
echo date("F", strtotime($d));
Still don't need an array!

Posted: Fri Jul 28, 2006 9:33 am
by anyday
thanks that worked great

Posted: Fri Jul 28, 2006 9:48 am
by jamiel
Bit of a hack though if you just copied and pasted his code... use this rather.

Code: Select all

function getMonthAsString($month)
{
    $unix_timestamp = mktime(null, null, null, trim($month, '0') + 1, null, null);
    return date("F", $unix_timestamp);
}

Posted: Fri Jul 28, 2006 10:57 am
by ronverdonk
My only point was that you don't need an array to get to a month description.