Date Convert
Moderator: General Moderators
Date Convert
anyone know how to convert a unix style 07,08 date to english like jan, feb, mar?
-
AngryPanda
- Forum Newbie
- Posts: 16
- Joined: Wed Jul 19, 2006 12:18 am
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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');
?>- ronverdonk
- Forum Commoner
- Posts: 34
- Joined: Sat Jun 10, 2006 7:06 am
- Location: Netherlands
What's wrong with this?
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?
It converts a unix timestamp to the full month and that is what you wanted, hmm?
Code: Select all
<?php
echo date("F", time());
?>- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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.
- ronverdonk
- Forum Commoner
- Posts: 34
- Joined: Sat Jun 10, 2006 7:06 am
- Location: Netherlands
Still don''t need an array
You can if you just insert the month into a date field, like this: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.
Code: Select all
$m="08";
$d="2000-$m-04";
echo date("F", strtotime($d));-
jamiel
- Forum Contributor
- Posts: 276
- Joined: Wed Feb 22, 2006 5:17 am
- Location: London, United Kingdom
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);
}- ronverdonk
- Forum Commoner
- Posts: 34
- Joined: Sat Jun 10, 2006 7:06 am
- Location: Netherlands